Forums

wp list categories, HOW TO put html tags around show_count (3 posts)

  1. mediabros
    Member
    Posted 2 years ago #

    Hi There,

    I don“t qiuet understand how to put some html tags ( g.e. <span> 4545 </span>) around the show_count output.
    i use

    <?php 
    
    wp_list_categories('sort_column=name&sort_order=asc&style=list&children=true&hierarchical=true&title_li=0&show_count=1'); 
    
    ?>

    to output

    <li><a>Grafisch Ontwerp</a> (11) </li>

    What i want is:

    <li><a>Grafisch Ontwerp</a> <span>(11)</span> </li>

    Any one has got a clue?

  2. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    there is an article in the codex on how to remove the brackets around the count:
    http://codex.wordpress.org/Template_Tags/wp_list_categories#Remove_Parentheses_from_Category_Counts

    expand this to exchange the brackets for brackets plus spans:

    <?php
    $variable = wp_list_categories('sort_column=name&sort_order=asc&style=list&children=true&hierarchical=true&title_li=0&show_count=1&echo=0'); 
    
    $variable = str_replace('(', '<span>(', $variable);
    $variable = str_replace(')', ')</span>', $variable);
    echo $variable;
    ?>
  3. mediabros
    Member
    Posted 2 years ago #

    Thanks alot, worked like a charm!

Topic Closed

This topic has been closed to new replies.

About this Topic