List posts by Sub-category and category in WordPress


WordPress allows a hierarchy of parent Category divided into multiple sub-categories. Every post belonging to parent category can also belong to multiple sub-categories. By default, these posts are displayed in alphabetical order but you can group these posts by sub categories and then display them. This is called sub category wise list of  Wordpress posts.category_post

A classic example can be seen here . On this real estate site, all properties are sorted by their locations and every location is a sub category of the parent category called ‘Our Locations’.

There is no direct way to generate a sub category wise list of posts in WordPress. Here is a code snippit that can help you. This works for category pages.

example

 

Advertisements

COMMENT PLEASE..!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s