Hi, how do I get the category (ID) of the actual displayed single or category page?
I only define ONE category to each article!
Hi, how do I get the category (ID) of the actual displayed single or category page?
I only define ONE category to each article!
In a category template:
$cat = get_query_var('cat');
echo $cat;
In a single type template and in The Loop see example in the article get_the_category.
okay thanks
I now get the cat ID using this piece of code:
$category = get_the_category();
echo $category[0]->cat_ID;
but this
if ($category[0]->cat_ID = 113) {
...
} elseif ($category[0]->cat_ID = 122) {
...
}
wont work..
kay thanks
this works:
$category = get_the_category();
$myCat = $category[0]->cat_ID;
if ($myCat == 113) {
...
} elseif ($myCat == 122) {
...
}Its because you arent using an operator, you are checking to see if the category was assigned. This is what you should be doing:
$category = get_the_category();
if ( $category[0]->cat_ID == 3 )
{
soSomething();
}This topic has been closed to new replies.