WordPress.org

Support

Support » How-To and Troubleshooting » How can I list categories hierarcical for a post?

How can I list categories hierarcical for a post?

  • I have a post which is related to 3 categories, top level category, city and street.

    I want to display the categories in the following order: City > Street (excluding top category)

    The following code displays the categories in alphabetical order:

    foreach((get_the_category()) as $category) {
        echo $category->cat_name . ' >';
    }

    The function get_the_category has no means of displaying it parent / child order.

    So how can I display the categories in parent / child order like wp list categories ?

    PS. No, I can’t use wp_list_categories() because it has no relation the the post and lists all parent / child categories.

    Any help appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Looks like 2.6 bugs are dominating this forum right now. But I’ll bump this question anyway 🙂

    Is the solution for my problem to do a direct query to the database?

    yes, this issue has been present for some time now, and is most annoying.I have as yet not figured a fix. I think it’s up to the WP team to sort out.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How can I list categories hierarcical for a post?’ is closed to new replies.
Skip to toolbar