How to choose different page templates for different pages

Source: Internet
Author: User
Tags php template

Imitation of an enterprise station when found that the station with a lot of page pages, and the individual page style is not the same, and different from the post page, in fact, the difference is that each page xhtml+css different, the key is the page template selection problem, Heng Ning summed up the following two methods.

The first type:
Copy, paste, and rename the page.php under the theme root directory to page-slug/id.php.
Slug is the alias for page pages, note: Aliases are English or pinyin.
ID is the ID number for page pages.
For example: page-zaixianlianxi.php or page-1.php.
The reason for this naming is to tell WordPress that this file is page pages.
Of course, it is not necessary to copy the contents of page.php other can also be customized for the differences, of course, HTML and CSS technology.
To open page-1.php with a DW or other editor, add a template description at the beginning, with the following code:

Information!

<? PHP /* Template Name: Join conditions */?>

This is the declaration that this file is a page template file, which will automatically appear in the page edit area to the right of the "page properties" of the "template" drop-down menu, if you do not see:

When the template is created, a template called "affiliate condition" will appear in the "Template" drop-down menu, which can be selected and published (updated), which may be placed in the navigation or other location. Instead of calling the page.php template by default, the page-1.php template is used to display the content of the page when clicked.

The second type:
Let WordPress automatically select the page template, this method does not use "template declaration", but must ensure that your page alias or ID number and template file alias or ID number consistent, otherwise open the page there is nothing.

Without the declaration can be opened, but not in the "template" drop-down menu, but just become a standalone template, and the page template of the statement can be used to edit other pages when the same template can be selected, according to their own needs to choose, (⊙o⊙) ... This seems to be a normal Site page pages are not used much.

That's right! Need to note that the priority of the WordPress alias is higher than the ID number, by default, WordPress first find the alias and then find the ID, Heng Ning suggested the choice of alias method is better, including in the code is also the same, so high versatility, Code in the use of aliases in the installation of the debugging site when you do not have to modify, because the alias is written dead, so as to avoid user modification, just need to add the corresponding category category directory, page pages, tag tags in the wordpress background, and modify their aliases can be, You can write a use of the document to tell users are those aliases and corresponding changes, but if it is the ID will be to modify the corresponding ID number in the template, if the project volume is very inconvenient, is not conducive to user experience, is not conducive to maintenance. Warning! Another note: page-xxx.php after the alias is not too long if more than 14 characters will appear the problem of the call does not come out! Pro-Test!

How to choose different page templates for different pages

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.