• Hi,

    When wordpress show categories of a post it do it in alphabetical order, but is there some way to make parent->child categories prioritized ?

    For example let say I have a main category “Software” with a child “Internet” that have itself two childs “Security” and “Firewall”.

    Now if I create a post will all thoses categories checked the post will show “Category : Firewall, Internet, Security, Software” instead of what I would like “Software, Internet, Firewall, Security”.

    regards.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Actually, I think the categories are displayed in ID order. It just so happens that, in your case, that’s also the alphabetical order. There’s no parameter to alter this ordering in the_category() but you could perhaps try using get_the_category() to get the categories for a post in an array and then sort the array alphabetically before displaying the category links.

    <?php
    $catlist = get_the_category();
    asort($catlist);
    $tot = count($catlist);
    $n = 0;
    foreach($catlist as $category) {
        $n++;
        echo '<a href="' .$category->category_nicename. '">' . $category->cat_name . '</a>';
        if( $n < $tot ) echo ', ';
    }
    ?>
    Thread Starter dodfr

    (@dodfr)

    @esmi,

    Thanx for your answer but actually WordPress already show it alphabeticaly sorted when the Post is displayed in main page or as single post, but I don’t want it to be like that, I want it to show parent-to-child sorted categories and if post is part of categories at same level, then do an alphabetical sort.

    regards.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Category priority problem’ is closed to new replies.