Different template files are called for different wordpress categories
When creating wordpress multi-column templates, different templates are called for different categories. For example, if my blog has Classification PHP and ASP technologies, different classification templates need to be called for each category, after finding a simple call method, let the summer blog teach you how to call different categories.
1. Call different templates for different categories
<? Php
$ Post = $ wp_query-> post;
If (in_category ('7 & prime ;))
{
Include (TEMPLATEPATH. '/archive-view.php ');}
Else if (in_category ('12 & prime ;))
{
Include (TEMPLATEPATH. '/single12.php ');
}
Else if (in_category ('42 & prime ;))
{
Include (TEMPLATEPATH. '/single42.php ');
}
Else {include (TEMPLATEPATH. '/archive-other.php ');
}
?>
The above code is taken from a piece of code on the network and put the code into the topic's classification file archive. php, in_category ('7 & prime;) in the middle of the digital code is the classification ID, which can be seen in the background Classification Directory, while the archive-view.php is the template file, you need to create a single-View. php files can be called.
2. Different articles call different templates by category
Different templates are called in different categories. The following articles also need to call the template of the current category to see the implementation method below,
<? Php
$ Post = $ wp_query-> post;
If (in_category ('7 & prime ;)){
Include (TEMPLATEPATH. '/single-view.php ');
}
Else if (in_category ('3 & prime ;))
{
Include (TEMPLATEPATH. '/single-case.php ');
}
Else if (in_category ('42 & prime ;))
{
Include (TEMPLATEPATH. '/single42.php ');
}
Else {include (TEMPLATEPATH. '/archive-other.php ');
}
?>
And wordpress different categories to call different templates of the file is basically the same, is to call the template file single-view.php is different, this also needs to create, so that you can call. Of course, this code should also be placed in single. php on the document template page.
3. Call different templates on the homepage.
To call a separate template on the homepage, you can add the following code to the archive. php file.
<? Php
If (is_home () | is_front_page () {?>
Include (TEMPLATEPATH. '/home. Php ');
<? Php }?>
If you need different single pages or website tag to call a separate template, the above parsing code can be used on the page and tag template.Face, you can try to modify it yourself ~~
Different wordpress articles call different template files
Find the following code in single. php on the article page:
<? Php
Get_header ();
?>
Modify it to the following code:
<? Php
$ Header = get_post_meta ($ post-> ID, "header", true );
Get_header ($ header );
?>
In this way, when we release the article, add custom field header, custom field value is 04ie, after adding, the custom template called is header-04ie.php, at this time we need to create a new header-04ie.php header file to call as a template. The above call replaces the header template file. Of course, the template principles on the sidebar comment page are the same.