I searched far and wide (on here & Google), reading about how to have multiple single.php pages for different categories of posts. The consensus was to do something like this:
<?php
/*
Template name: Single
*/
?>
<?php
$post = $wp_query->post;
if ( in_category('blog') ) {
//echo 'category is 3 which is blog-single';
include(TEMPLATEPATH . '/blog-single.php');
}
elseif ( in_category('projects') ) {
//echo 'category is 4 which is project-single';
include(TEMPLATEPATH . '/project-single.php');
}
else {
//echo 'category is neither of the above so default is selected';
include(TEMPLATEPATH . '/project-single.php');
}
?>
But for whatever reason this is not working for me. It always goes to the else
statement when I click on a blog post of a project post. The page above is called single.php
and the two other pages are named project-blog.php
& blog-single.php
exactly.
I attempted to comment out the include(TEMPLATEPATH..
and just echo some text, but it always would go straight to the else
no matter which post I click on.
I have triple checked the the category ID is correct for each if
statement (see image below).
I also tried to make it is_category
instead of in_category
as well as also trying to put the category name in place of the category_id (for example blog or projects).
What am I doing wrong? Here’s a screen shot of the URL from when drilling into a Category showing that the category_id (tag_id) is indeed correct. I hope this is enough info…
edit:
I even tried this…
if ( in_category('blog') || is_category(blog) || is_category('blog') || in_category(blog) || is_category(3) || is_category('3') || in_category('3') || in_category(3) ) {
And I changed my permalinks to include the category in them. So now project-single is working but not blog…