WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm testing something which needs to display posts within wp_list_categories(). Basically I want to display all content for a taxonomy.

I'm pretty sure that to make it happen I have to alter the WP class or function that handles categories and stuffs like this. Is that the way?

EDIT: I've opened the core file that contains wp_list_categories(). It's in wp_includes in the file called category-template.php

How can I alter this?

EDIT 2: there's a filter wp_list_categories

share|improve this question
up vote 0 down vote accepted

Off the top of my head, you can achieve the desired effect in two different ways.

Extend the Category Walker

Extend the Walker_Category() class and overwrite the start_el() method with similar code that retrieves a list of posts in the category being processed and displays them in an unordered list within the category's <li> element. To use your new walker class, pass it's name in the walker argument of wp_list_categories().

Procedurally Process Cateogries

Rather than having wp_list_categories() echo out a list of categories, set the echo argument to false, set a variable to the function call's return value, and use the PHP regular expression and string functions to modify the markup as needed.

The second solution can alternately be achieved by hooking into the wp_list_categories filter, which receives the same generated markup as an argument that wp_list_categories() returns when echo is set to false.

share|improve this answer
Thanks just wanted to be sure. I'm gonna go with procedural in this case ^^ – JMau Mar 11 '14 at 20:49
Sure thing! Tricky part about the procedural approach is that you'll have to figure out how to extract the term from the list-item so that you can query it for posts (I'm not positive, but I think that the term_id may be the number appended to the cat-item-{number} CSS class). When extending the Walker_Category class, the term_id is immediately available in the start_el() method in the form of the $id argument. – bosco Mar 11 '14 at 21:01
yeah but it's deprecated. – JMau Mar 11 '14 at 21:06
Huh... good catch!! It's not deprecated, but it's definitely not used - looks like that's just there to properly extend the Walker class. Annoying that it's not marked as unused. But the term_id is still available via $category->term_id. – bosco Mar 11 '14 at 21:20
I finally get through this with 1rst method XD. Thanks again. – JMau Mar 11 '14 at 21:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.