Answer the question
In order to leave comments, you need to log in
How to make multiple single.php templates on Wordpress?
Good afternoon.
I don't know much about php, please help.
Once there was a task to make a separate single.php template for one category. At that time, I came across the following solution on the net:
<?php
$test = array(3);
if ( have_posts() ) { the_post(); rewind_posts(); }
if ( in_category($test)) { include(TEMPLATEPATH . '/single-test.php'); }
else {
include(TEMPLATEPATH . '/single-defolt.php');
}
?>
<?php
$test = array(3);
if ( have_posts() ) { the_post(); rewind_posts(); }
if ( in_category($test)) { include(TEMPLATEPATH . '/single-test.php'); }
else {
$test = array(1,4,5,6,7,10);
if ( in_category($test)) { include(TEMPLATEPATH . '/single-defolt.php'); }
else {
include(TEMPLATEPATH . '/single-defolt-2.php');
}
}
?>
Answer the question
In order to leave comments, you need to log in
single.php is not about category pages at all,
here is a detailed diagram to help you: wphierarchy.com
There is a plugin that allows you to assign different templates to Posts. Custom Post Templates
Look at the idea, if you have the Custom Post Types plugin (a plugin, I personally have it, a must-have), or manually make the custom field "Post Template" a checkbox and use it later in a loop with an if construct, only ABOVE in the VI for this special function get_template_part();
And in general, it is possible to connect in the following, correct way:
category-3.php For a category with ID 3
category-228.php For a category with ID 228
category.php - for ALL remaining categories
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question