Category Lists

Much like wp_list_pages(), wp_list_categories() lets you customize the category list in a number of ways. By default, it lists all your categories in alphabetical order. A few of the function's optional parameters are shown in Listing 6-29.

Unlike pages, categories don't have a menu order. You can add this feature with the My Category Order plugin.

Listing 6-29. Using the wp_list_categories function

<!-- all categories in alphabetical order --> <ul> <?php wp_list_categories(); ?> </ul> <!-- all categores in menu order: My Category Order <ul> <?php wp_list_pages('sort_column=menu_order'); <!-- show only parent categories --> <ul> <?php wp_list_categories('depth=1'); ?> </ul>

You could combine page and category lists by using a filter. I'll talk more about filters in Chapter 10, but in the meantime, Listing 6-30 shows a quick filter function that could be placed in your functions.php file.

Listing 6-30. Appending the category list to your page lists function add_category_list($pagelist) {

$cats = wp_list_categories('echo=0&title_li='); return $pagelist.$cats;

add_filter('wp_list_pages', 'add_category_list');

0 0

Post a comment