Support » Fixing WordPress » Category parent shows after sub-category

  • Resolved crsuperman34

    (@crsuperman34)


    Unfortunately my problem exists on my localhost so I can’t forward you to the website.

    Check the following screenshots. ‘design’ is a parent of ‘work’ same as ‘Travel’ is a parent of ‘New Zealand’
    http://www.pommebelle.com/code_files/images/categories.png
    http://www.pommebelle.com/code_files/images/tags.png

    I’m using this code:
    $category = get_the_category();
    $wut = $category[0]->cat_name;
    to pull the parent category.

    ‘New Zealand’ (or any sub-category of ‘travel’) gets returned with 0 whereas it should be the parent, ‘travel’ that gets returned. Is there anyway to change the order? Why is it wrong to begin with?

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

    (@alchymyth)

    to pull the parent category.

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

    crsuperman34

    (@crsuperman34)

    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).

    crsuperman34

    (@crsuperman34)

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

    crsuperman34

    (@crsuperman34)

    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.

    crsuperman34

    (@crsuperman34)

    $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 ‘Category parent shows after sub-category’ is closed to new replies.