free tuts

Unlike normal posts categories list where categories are populated with simple function

or just with default widget “Categories”, CPT categories require more work to be populated on page or on sidebar.

Assuming that we already created CPT function (or better plugin) where we registered CPT and related taxonomy (categories and tags or categories only–depends on needs of concrete website or theme), now we need to populate taxonomy. Say, we want to populate list of CPT categories in sidebar of specific page. After registering dedicated sidebar area in functions.php we add a function which will populate a list of categories and subcategories in this very sidebar.

As usual, I create a separate php file for specific sidebar where I want to put content relevant to specific page (or set of pages–say, I want to add Shop Categories on Shop Page, Single Shop Posts and so on).

So, in a file “shop-sidebar.php” we put this portion of code:

where “itype” is categories taxonomy. We populate both parent categories and subcategories.

Now, entering the Services page we see the populated list of Shop categories.

All we need to do now is to style the list properly adding styles to styles.css and we get this visual result:


Styles of category list:

View it live