That’s what I also thought, but your solution still keeps me giving two categories.
I read that some of the functions you can’t use inside or outside The Loop so i guess that’s the problem (i’m in header.php and i didn’t call <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> so i think I’m outside the loop – is that right?).
https://www.ads-software.com/support/topic/single_cat_title-not-displaying-anything
I temporarily solved it with this:
foreach (get_categories('exclude=1&parent=0&hide_empty=1&number=6') as $category) {
if (is_single()) {
$cat_flag = false;
foreach(get_the_category() as $cat)
if ($category->cat_ID == $cat->cat_ID)
{
$cat_flag = true;
break;
}
if ($cat_flag) {
//do my code
}
}
But simplier solution would be nicer..