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);
get_category_parents()needs the current category. This led me to use get_the_category().
Here is where the problem starts.
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.
- The topic ‘Category Order in Posts’ is closed to new replies.