• Resolved misuko

    (@misuko)


    I would like to edit my single.php to have the post meta display the category of the post — except I would like this to display only the parent category.
    From what I can tell the only function that achieves this is get_category_parents, except not really. get_category_parents, however, also displays the child category, which I do not want.

    Any solutions to this, please advise.

Viewing 1 replies (of 1 total)
  • Thread Starter misuko

    (@misuko)

    Okay, solved it myself. I used a VERY primitive method.

    The code, in case anyone needs to do anything similar in the future.

    <?php
    $category = get_the_category();
    $parent = get_cat_name($category[0]->category_parent);
    if (!empty($parent))
    {
    echo '<a href="', bloginfo('url'), '/', $parent, '/">', $parent, '</a>';
    }
    else
    {
    echo the_category(', ');
    }
    ?>

Viewing 1 replies (of 1 total)
  • The topic ‘Display only parent category in post’ is closed to new replies.