Forums

Customizing Category Widget (2 posts)

  1. maple1249
    Member
    Posted 1 year ago #

    Hi all,

    I'm developing my own theme, and in doing so, need to structure the category sidebar widget like so:

    <ul>
    <li>
    <a>CATEGORY NAME<span>PostCountWithOUTParenthesis</span></a>
    </li>
    ...
    </ul>

    And the default way it works is:

    <ul>
    <li>
    <a>CATEGORY NAME</a> (PostCount)
    </li>
    </ul>

    I was wondering if anyone could help me out with this? Thank you - it's greatly appreciated!

  2. alchymyth
    The Sweeper
    Posted 1 year ago #

    try to add something like this to functions.php of your theme:

    add_filter('wp_list_categories', 'cat_count_span_inline');
    function cat_count_span_inline($output) {
    $output = str_replace('</a> (','<span> ',$output);
    $output = str_replace(')','</span></a> ',$output);
    return $output;
    }

    http://codex.wordpress.org/Plugin_API/Filter_Reference
    http://codex.wordpress.org/Template_Tags/wp_list_categories

    it will output your structure for all the wp_list_categories() in your theme, where 'show post count' is ticked.

Topic Closed

This topic has been closed to new replies.

About this Topic