Support » Fixing WordPress » How to print out current category when a post has SEVERAL?

  • I have my menus running fine dynamically through WordPress, so when I click a certain category or subcategory, I get all the correct posts displayed.

    But, I want to have it print out the current category as a title on the page.

    Currently I have this, but it just spits out whichever category it feels like, apparently:

    <h2>
      <?php $category = get_the_category();
      echo  $category[0]->cat_name;
      ?>
    </h2>

    My posts have multiple categories and subcategories, so the above code just chooses one, but I have no control over it. I want it to display the correct category that WordPress is currently cycling through depending on what you’ve clicked. I’ve got the post content working fine, just this title is elusive for some reason.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘How to print out current category when a post has SEVERAL?’ is closed to new replies.