0

How can I wrap the "show_post_count" between a div? (from the wp_get_archives())
Do I need to edit the function for that?

Or could I do something like this with pseudo css?

<div class="post_count">
    <a href="http://www.finsens.salescaredev.nl/2012/03" title="March 2012">March 2012</a>&nbsp;(1)
</div>

Css:

.post_count a:after (all the content in the div and after the .post_count){
 float: right;
}

1 Answer 1

5

You can style the post count differently via CSS with the given markup. It’s not very practical but by making use of the cascading nature of CSS, you could do this:

.post_count { /* styles for the post count number in parenthesis */ }
.post_count a { /* styles for the link, be sure to override properties from the line above if needed */ }

Whatever you do, don’t edit the wp_get_archives() function directly. You will lose your changes when WP gets updated. That function does not provide any useful filters for doing what you want.

If you want to wrap the post count in an additional HTML element, try this approach. By returning the output of wp_get_archives() you have the option to tweak the markup and target the count directly via CSS (.post_count .count):

// Generate the default list
$html = wp_get_archives( array(
    'show_post_count' => true,
    'echo' => false,
) );
// Wrap the post count in a span element
$html = preg_replace( '~(&nbsp;)(\(\d++\))~', '$1<span class="count">$2</span>', $html );
// Output the result
echo $html;

Note: I am well aware that parsing HTML using regular expressions is considered evil. No need to remind me about that. I’m all ears for better solutions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.