A simple method for obtaining the page ID of the template used in WordPress. wordpressid_PHP tutorial

Source: Internet
Author: User
Tags php template
Wordpressid is a simple method for obtaining the page ID of the template used in WordPress. WordPress provides a simple method to obtain the page ID of the template used. what is wordpressid? By default, WordPress uses page. php in the topic directory as the template to display the page ID of the template used in WordPress. wordpressid

What is a template? By default, WordPress uses the page under the topic directory. php is used to display pages as templates, but sometimes we need different templates to display pages, such as logon, registration, and contribution pages. These pages are different from common pages, at this time, WordPress provides a page template that allows developers to customize the appearance and functions of WordPress pages.
Page template php file matching

In WordPress, the template used by the page is recorded through a custom column. the custom column name is _ wp_page_template, and the value is the template File name:

If the default template is page. php, the value of _ wp_page_template is default. If the default template is used from the beginning, WordPress does not add this custom topic.
If it is a custom page template under the topic 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 and is a hidden custom column, you cannot see this field in the custom column on the page editing page.

Obtain the page ID using the page template

I created a new login page template named login. php, and there are pages in the background using this template, then I can use the following function to obtain the use of login. the page id of the php template:

Function get_page_id_from_template ($ template) {global $ wpdb; // I have no choice but to use the same template for multiple pages. $ 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 ;}

Many may ask, what do I do when I obtain the page id? Can I use the id to obtain the link to the logon page:

> Logon

Someone may ask, can I obtain the page id through the page title and alias? If the topic is used by the customer, do you know what kind of title the customer will use? Force the customer to use the title you specified? Then you are too unfriendly!

Articles you may be interested in:
  • How to introduce a template file for WordPress topic creation
  • Get the header template and the bottom template in WordPress topic writing
  • Describes the PHP functions used in WordPress to obtain comment templates and search forms.

What is a template? By default, WordPress uses page. php in the topic directory to display the page as a template...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.