WordPress.org

Ready to get started?Download WordPress

Forums

showing categories and subcategories using THE_CATEGORY ?? (4 posts)

  1. podpersonjason
    Member
    Posted 9 years ago #

    hey there.

    i'm trying to find a way to use the "<?php the_category( ); ?>" tag to display the hiarchical relationship between my category and its subcategory.

    to clarify: if a post is in the subcat "monkeys" whose parent category is "primates" i want the_category to return "primates > monkeys". obviously the > sign is arbitrary. the point is that the_category only shows the category a post is placed in, and makes no reference to the parent category? is there a way around this? besides posting the entry in both "primates" and "monkeys"?

    thanks!

  2. oriecat
    Member
    Posted 9 years ago #

    I think if you use something like <?php the_category(', ','single') ?> then it will show both the parent and child, separated by a /.

    See here:
    http://codex.wordpress.org/Template_Tags/the_category

  3. podpersonjason
    Member
    Posted 9 years ago #

    yes, that is correct, but - and feel free to call me anal - i am really hoping to find a way that will list them and let me control whether it's a link or just a list, and also lets me dictate the seperating character.

    <?php the_category_rss(' , ',' single ') ?> returns the category from the post and its parent, but only as a single link and only seperated by the \ ... i'm hoping to find something more flexable.

  4. jalenack
    Member
    Posted 9 years ago #

    the_category is meant to only display the link of the post it is referenced to. You are looking for another wp function:

    wp_list_cats() - It makes a nice little list of all your categories, with links.

    <h2>Categories</h2>
    <ul>
    <?php wp_list_cats(); ?>
    </ul>

    http://codex.wordpress.org/Template_Tags/wp_list_cats

Topic Closed

This topic has been closed to new replies.

About this Topic