• bpoulsendk

    (@bpoulsendk)


    I want to list which categories are attached to a post.

    I have a parent category and several child categories..

    If I select the parent category and a child category and I want to list what categories I’ve attached to a post, how do I list those categories so they are sorted by ID and not alphabetically?

    My problem is in my sidebar I have a list of the last 10 posts in the parent category.
    However I want the list to include the name of the child category so the list looks like this:

    LAST 10 POSTS IN X CATEGORY
    —————————
    CHILD CATEGORY – POST TITLE
    CHILD CATEGORY – POST TITLE
    CHILD CATEGORY – POST TITLE
    CHILD CATEGORY – POST TITLE
    CHILD CATEGORY – POST TITLE

    and so on.

    My plan was just to use this:

    <?php $category = get_the_category();
    echo $category[1]->cat_name; ?>

    However as it sorts the categories by name, if I have a child category starting with a letter before the parent category it screws up and writes the parent category instead of the child category..

    Anybody has a suggestion?
    Thanks a lot in advance!

  • The topic ‘Listing categories by ID not alphabetically’ is closed to new replies.