In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "how to get the page ID of the template used in WordPress". In daily operation, I believe many people have doubts about how to get the page ID of the template used in WordPress. Xiaobian consulted all kinds of materials and sorted out simple and easy to use operation methods. I hope to answer the doubts of "how to get the page ID of the template used in WordPress"! Next, please follow the small series to learn together!
What is a template? By default WordPress uses page.php in the theme directory as a template to display pages, but sometimes we need different templates to display pages, such as login, registration and contribution pages, etc. These pages are different from ordinary pages. WordPress provides page templates that allow developers to customize the appearance and even functionality of WordPress pages.
Page template php file matching
WordPress is a custom column to record the template used by the page, custom column name: _wp_page_template, the value of the template file name:
If the default template is page.php, then the value of_wp_page_template is: default. WordPress will not add this custom column if it is the default template from start to finish
If it is a custom page template under the theme root directory, then the value of_wp_page_template is the file name, such as: page-login.php
If it is a page template under the theme subdirectory, then the value of_wp_page_template contains the path, such as: templates/page-login.php
Because the name of this custom column starts with an underscore, it belongs to a hidden custom column, so you can't see this field in the custom column of the page edit page.
Get page ID from page template
I created a login page template, named login.php, and there are already pages using this template in the background, then I can use the following function to get the page id using login.php template:
function get_page_id_from_template($template) { global $wpdb; //multiple pages using the same template I can't do anything $page_id = $wpdb->get_var($wpdb->prepare("SELECT `post_id` FROM `$wpdb->postmeta`, `$wpdb->posts` WHERE `post_id` = `ID` AND `post_status` = 'publish' AND `meta_key` = '_wp_page_template' AND `meta_value` = %s LIMIT 1;", $template)); return $page_id;} At this point, the study of" how to get the page ID of the template used in WordPress "is over, hoping to solve everyone's doubts. Theory and practice can better match to help you learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.