WordPress.org

Support

Support » How-To and Troubleshooting » Category Order in Posts

Category Order in Posts

  • So I’ve been customizing the 3.5.1 TwentyTwelve theme for a few days now, and am bumping into an issue with categories.

    I have a plugin that loops on my homepage showing posts based on specified tags or categories. I wanted to extend it so that it also shows to what category hierarchy that post belongs to.

    I found the following code that helps me get an array of the category hierarchy into an array

    $categories = get_category_parents($cat, FALSE, '|');
    $parent_category = explode('|', $categories);

    .. however get_category_parents() needs the current category. This led me to use get_the_category().

    Here is where the problem starts.

    Using get_the_category(get_the_ID()) lists the category, however they are organized alphabetically, which makes it impossible to pin point the specific levels of category. First I thought I was doing something wrong, but then I realized it’s listing them the same way they’re shown in the ALL POSTS page.

    here is an example: <img src=”http://ishowbusiness.com/img/WP_Cats.jpg” />

    I know wp_category_list() has sorting capabilities, but I believe it doesn’t work for this.

    Essentially all I need is the category ID of the post being printed in the loop so that I can use my other snippet… unless you guys think there is a better way.

    Any thoughts?

Viewing 3 replies - 1 through 3 (of 3 total)
  • esmi

    @esmi

    Forum Moderator

    Do not edit the Twenty Twelve theme. It is the default WordPress theme and having access to an unedited version of the theme is vital when dealing with a range of site issues. First create a child theme for your changes. Or use a custom CSS plugin.

    I’ll look into that, but I do have backup of the original files, and like I mentioned I’m extending a plugin… which is really the topic of the post.

    Any thoughts on that? Thanks.

    btw. I’ve duplicated TwentyTwelve, restored my backup on the original and left my modified files on the Child. Thanks

    .. so, about that category thingy, any thoughts?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Category Order in Posts’ is closed to new replies.