Showing Only WordPress Top Categories
Posted by sky | Tags: Php, WordPress
My sub-categories links are not working! I decided to show only the top categories on my sidebar. The following describes how I do it: Modify function get_categories in category.php- Add show_top option in $defaults.
$defaults = array('type' => 'post', 'child_of' => 0, 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => true, 'include_last_update_time' => false, 'hierarchical' => 1, 'exclude' => '', 'include' => '', 'number' => '', 'pad_counts' => false, 'show_top' => false);
- Add to the sql where criteria if $show_top is true.
if ($show_top) $where .= ' AND category_parent = 0';
- Modify my sidebar.php
<?php wp_list_cats('sort_column=name&hierarchical=0&show_top=true') ?>