The following is the specific implementation code. Take it away if you need it. The code is ready for use by myself...
The code is as follows: |
Copy code |
<? Php If (in_category ('post ')){ Include (TEMPLATEPATH. '/single-post.php '); } // Elseif, in one judgment, tries to add judgment to copy the code Elseif (in_category ('plugin') {// pro is the alias of category Include (TEMPLATEPATH. '/single-plugin.php '); } // Elseif ends Else { Include (TEMPLATEPATH. '/single-all.php '); } ?> |
The post in in_category ('post') also supports ID, that is, writing in_category ('3 & prime ;).
The other is similar. We can directly modify the style.
IF IN_CATEGORY condition label
First, copy the two single. Php files named "single1.php" and "single2.php" respectively ". Then, delete all the content in the original single. Php file and replace it with the following code:
The code is as follows: |
Copy code |
<? Php $ Post = $ wp_query-> post; If (in_category ('9 & prime ;)){ Include (TEMPLATEPATH. '/single2.php '); } Else { Include (TEMPLATEPATH. '/single1.php '); } ?> |
Check the log. If the log belongs to the category ID9, single2.php is displayed. If not, single1.php is displayed.
You can also use more condition statements to specify different styles and content for different classes. For example:
The code is as follows: |
Copy code |
<? Php $ Post = $ wp_query-> post; If (in_category ('9 & prime ;)){ Include (TEMPLATEPATH. '/single9.php '); Elseif (in_category ('12 & prime ;)){ Include (TEMPLATEPATH. '/single12.php '); Elseif (in_category ('42 & prime ;){ Include (TEMPLATEPATH. '/single42.php '); } Else { Include (TEMPLATEPATH. '/single1.php '); }} ?> |
Because I don't want to change these two single template files, but just add an extra style table to the second file single2.php, then I create two header template files, just like copying single. same as php. Then add the link to the external style sheet at the top of the second header file:
The code is as follows: |
Copy code |
<Style type = "text/css" media = "screen"> @ Import URL ('/wp-content/themes/mytheme/style.css '); @ Import URL ('/wp-content/themes/mytheme/cssstyles.css '); </Style> |
Next, we need to call header2.php in the second single2.php:
The code is as follows: |
Copy code |
<? Php /* Don't remove this line .*/ Require ('./wp-blog-header.php '); Include (get_template_directory (). '/header2.php' ?> |