Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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;
}
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.