Show only the categories tied to a Single post (2 posts)

  1. woody24
    Posted 2 years ago #

    On the homepage I am showing Posts previews. I only want to show the Featured Image, Title with permalink, and the Category of the State the post is tied to. So that when someone clicks on the state category link, they see all the other posts tagged in the same state category.

    The problem I am having is making only that one state show up for that post. Right now all states categories that have a post tied to them are showing up under each post. Its essentially just showing the entire subcategory.

    I need to make it only show the one state that that post is tagged in. Here's the code I currently have. What other argument do I need to make it work the way I want?

    <?php wp_list_categories('style=none&orderby=id&use_desc_for_title=0&child_of=6'); ?>

    And when I say State, I mean of the 50 States of the USA.

  2. woody24
    Posted 2 years ago #

    Ok, figured out that I need to use get_the_category instead. But need to put in a parent category. How does this 'category_parent' get inserted into this:

    $category = get_the_category();
    echo '<a>term_id ).'">'.$category[0]->cat_name.'</a>';

Topic Closed

This topic has been closed to new replies.

About this Topic