Problem: Parent category shows child name (2 posts)

  1. hitchy.ali
    Posted 5 years ago #

    Hey guys,

    The problem can be seen here: http://alihitch.com/category/all-tutorials/

    The child categories of 'all tutorials' display their name correctly, but oddly when looking at the 'all tutorials' category, it displays the name of one of the child categories but I have no idea why.

    Below is the code for this particular section.

    <?php elseif ( is_category() ) : ?>
            	<div class="a-year">
    				foreach((get_the_category()) as $category)
    				  $postcat= $category->cat_ID;
    				  $catname =$category->cat_name;
    				  echo $catname;
                </div><!-- a-year -->
  2. Michael
    Forum Moderator
    Posted 5 years ago #

    in category archives, you can use single_cat_title(); to show the category name.


    get_the_category() will get post categories:


    (using this outside the loop (without a parameter) will have unpredictable results)

Topic Closed

This topic has been closed to new replies.

About this Topic