1
votes

Having a few issues in customizing a WordPress categories list and would appreciate any examples of how I can achieve the following:

  1. I have created a WordPress categories list that shows the count for all categories. However, I am unable to show the count for show_option_all ie show the total number of posts for all categories combined in the same way that all the other categories display the post count?

  2. How can I add a separator between each category list item ie between each li?

  3. If category list appears on a particular page, is their a way of giving a specific category within the list, an active state?

Please see existing code below:

<ul>            
        <?php
        $categories = wp_list_categories('title_li=&show_count=1&echo=0&child_of=18&show_option_all=ALL');
        $categories = preg_replace('/<\/a> \(([0-9]+)\)/', ' <span class="count"><sup>\\1</sup></span></a>', $categories);
        echo $categories;
        ?>
</ul>

Any help would be appreciated.

EDIT: Ended up using the code below which achieved the desired results:

<ul>        
        <?php
        $categories = wp_list_categories('title_li=&show_count=1&echo=0&child_of=18');
        $categories = preg_replace('/<\/a> \(([0-9]+)\)/', '</a> <span class="count"><sup>\\1</sup></span></li><span class="separator">/</span>', $categories);
        echo $categories;
        ?>
        </ul>
1

1 Answers

0
votes

Use Like

<?php
$terms = get_terms('category'); /*Name Of category*/
foreach ( $terms as $term ) {
    echo $term->name.'<br/>  '.$term->count.'<br/>';
}
?>

Output

enter image description here