WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Category parent shows after sub-category

[Resolved] Category parent shows after sub-category

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Michael

    @alchymyth

    Forum Moderator

    to pull the parent category.

    this will pull the category of the post with the lowest category ID;

    Right but if I use $category[0]->cat_name; on the design category I get the parent ‘design’ returned. If I use it on the travel category I get the sub-category returned.

    Both Categories have only posts with equal depth: a parent and a sub. Yet, I get two different results.

    If you look at the screenshot of the admin posts page you see design listed first (before the sub) and Travel listed second (after the sub).

    nevermind, I understand. This code doesn’t do what I thought it does.
    I needed: get_category_parents($cat, FALSE, ”, TRUE)

    The sub category is listed first on Travel pages.
    if I use
    $mycategories = get_the_category_list();

    I’ll get:
    Sub Category, Parent on the travel category
    and
    Parent, Sub Category on the design category

    I need the list to always return Parent then Sub Category.

    $category = get_the_category();
    $parent = get_cat_name($category[0]->category_parent);
    if (!empty($parent)) {
    echo $parent;
    } else {
    echo $category[0]->cat_name;
    }

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] Category parent shows after sub-category’ is closed to new replies.