Forums

[resolved] Edit show count text on wp_list_categories (4 posts)

  1. kissanpentu
    Member
    Posted 2 years ago #

    I'd like to list my categories and show how many posts are in there. But: I use this code:

    <?php wp_list_categories('show_count=1&title_li='); ?>

    And the result is:
    * Category name 1 (15)
    * Category name 2 (17)
    * Category name 3 (25)
    * Category name 4 (2)
    * Category name 5 (32)

    I'd like to display it as:
    * Category name 1 (15 posts)

    I have no idea how to put anything after the number which shows the numbers. Anyone have any suggestion? Thx!

    [corrected title]

  2. MichaelH
    Volunteer
    Posted 2 years ago #

    Here's a useful example: wp_list_categories

  3. stvwlf
    Member
    Posted 2 years ago #

    One way to do it would be to capture the output of wp_list_categories in a variable and use PHP to replace occurrences of ) in that variable with " posts)" - then output the revised variable.

    something like this should do it

    <?php
    $list = wp_list_categories('show_count=1&title_li=&echo=0');
    $list = str_replace( ")", " posts)", $list );
    echo $list
    ?>
  4. kissanpentu
    Member
    Posted 2 years ago #

    Thx, great solution ;)

Topic Closed

This topic has been closed to new replies.

About this Topic