Search code examples
wordpresscategorieswp-list-categories

Is there an alternative to wp_list_categories


I would like to display a list of all categories, using their hierarchy. I want to use jquery to manipulate other objects when the categories are clicked, so I need to remove the links that are added by default.

wp_list_categories does this wonderfully, automatically adding hierarchy of the sub-categories and adding the nested lists. I just do not want the links that are added by default.

Is there an alternative to wp_list_categories which does not give each category a link to its respective page?

When I tried get_categories(), it did not respect the hierarchy of the categories.

Using latest WP version.


Solution

  • The output of teh wp_list_categories() function is passed through a filter, which you could use to modify the resulting HTML:

    $output = apply_filters( 'wp_list_categories', $output, $args );
    

    If you want to actually modify the HTML that is generated by the function, you can extend the Walker_Category class, a good explanation can be found here http://scribu.net/wordpress/extending-the-category-walker.html