I was able to find this code:
<?php
if (is_category(9)) {
// looking for category 9 posts
include(TEMPLATEPATH . '/single2.php');
} else {
// put this on every other category post
include(TEMPLATEPATH . '/single1.php');
}
?>
Can I just keep adding if statements? for each category before the else?
In other words… is this valid:
<?php
if (is_category(1)) {
// looking for category 1 posts
include(TEMPLATEPATH . '/single1.php');
if (is_category(9)) {
// looking for category 2 posts
include(TEMPLATEPATH . '/single2.php');
if (is_category(9)) {
// looking for category 3 posts
include(TEMPLATEPATH . '/single3.php');
if (is_category(9)) {
// looking for category 4 posts
include(TEMPLATEPATH . '/single4.php');
} else {
// put this on every other category post
include(TEMPLATEPATH . '/single.php');
}
?>
Almost…
if
elseif
elseif
elseif
else
On my single.php page I want to have the tab of the article’s corresponding category highlighted.
For posts, use in_category instead of is_category.
Great! I will try this! Where would I place this code?
I have tried the above code
<?php
if (is_category(11)) {
// looking for category 11 posts
include(TEMPLATEPATH . '/single11.php');
elseif (is_category(9)) {
// looking for category 2 posts
include(TEMPLATEPATH . '/single2.php');
elseif (is_category(9)) {
// looking for category 3 posts
include(TEMPLATEPATH . '/single3.php');
elseif (is_category(9)) {
// looking for category 4 posts
include(TEMPLATEPATH . '/single4.php');
} else {
// put this on every other category post
include(TEMPLATEPATH . '/singlegeneral.php');
}
?>
But am getting this error “Parse error: parse error, unexpected T_ELSEIF in /home/content/a/z/e/azelasko/html/wp-content/themes/embedded411/single.php on line 5”
brackets weren’t closed! Thank you for your help!
iridiaz, that in_category was key! Thank you!
That should be work fine
<?php
$post = $wp_query->post;
if ( in_category('5') ) {
include(TEMPLATEPATH . '/single2.php');
}elseif ( in_category('3') ) {
include(TEMPLATEPATH . '/single1.php');
} else {
include(TEMPLATEPATH . '/single.php');
}
?>