dbUNIT16
Member
Posted 3 years ago #
On my single.php page I want to have the tab of the article's corresponding category highlighted.
For example: http://embeddedcomputingsystems.com/
If the article is from "Boards" (the second tab next to "Home") then I'd like the Boards tab to be in the active state. I'm am guessing I'd use some sort of php if statement, like if category=3 then class="active" but am unsure of how to write this. I know nothing about php!
Can someone please help?
Thanks,
Jon
dbUNIT16
Member
Posted 3 years ago #
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?
dbUNIT16
Member
Posted 3 years ago #
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.
dbUNIT16
Member
Posted 3 years ago #
Great! I will try this! Where would I place this code?
dbUNIT16
Member
Posted 3 years ago #
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"
dbUNIT16
Member
Posted 3 years ago #
brackets weren't closed! Thank you for your help!
iridiaz, that in_category was key! Thank you!
hamidelgendy
Member
Posted 3 years ago #
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');
}
?>