Get Parent Category? (6 posts)

  1. Pete White
    Posted 5 years ago #

    Is there a way to make a header tag display a category and subcategory together, instead of just a single category?

    h2><?php _e('Vacation Rental Listings in','cp')?> <?php single_cat_title(); ?>, NC (<?php echo $wp_query->found_posts ?>)</h2>

    The above displays as "Vacation Rental Listings in (Subcategory), NC"

    I need it to display as "Vacation Rental Listings in (Parent Category), NC"

    Any direction you can provide would be greatly appreciated! =)

  2. Micah Cooksey

    Posted 5 years ago #

  3. Pete White
    Posted 5 years ago #

    Thanks for the reply! I tried that, but was unable to get it to display ONLY the parent. It would show the parent and child category, and show them as links. I need the parent only in a non-link format.

  4. Micah Cooksey

    Posted 5 years ago #

    Gotcha, sorry. I don't know of a template tag that will allow you to do that, although I'm sure it's possible. You could test out some of the category tags listed here: http://codex.wordpress.org/Template_Tags/the_category#Related

  5. Pete White
    Posted 5 years ago #

    ok thanks!

  6. JonMasterson
    Posted 4 years ago #

    I know this was a while ago, but here is what I came up with. It worked great for me. "$catParent" = parent category name

    <?php $category = get_the_category();
    $catParID = $category[0]->category_parent;
    $catParent = get_cat_name ($catParID);

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.