WordPress.org

Ready to get started?Download WordPress

Forums

Problem: Parent category shows child name (2 posts)

  1. hitchy.ali
    Member
    Posted 3 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">
    
                <h2>
    			<?php
    				foreach((get_the_category()) as $category)
    					{
    				  $postcat= $category->cat_ID;
    				  $catname =$category->cat_name;
    
    				  echo $catname;
    				}
    			?>
    			</h2>
    
                </div><!-- a-year -->
  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

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

    http://codex.wordpress.org/Function_Reference/single_cat_title

    get_the_category() will get post categories:

    http://codex.wordpress.org/Function_Reference/get_the_category

    (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