tags:

views:

73

answers:

1

I have the following code to display posts in Wordpress

<?php wp_get_archives('type=monthly&show_post_count=1'); ?>

How can I add a span class around the count so I can style it?

The above code produces this:

October (9) November (22) December (3)

I need to assign a span class to the count, and not entire output.

+1  A: 

Easiest option is with a little bit of CCS magic. At the moment, I am assuming your template code (for the archive block) is along the lines of:

<ul>
  <?php wp_get_archives('type=monthly&show_post_count=1'); ?>
</ul>

Firstly, add a class to your list:

<ul class="archiveList">
  <?php wp_get_archives('type=monthly&show_post_count=1'); ?>
</ul>

Secondly, add some lines to your CSS to style the relevant bits

.achiveList li {color: red;} /* This is the style for the post count */
.achiveList li a {color: blue;} /* This is the style for the link */

The Hard option is to set the "echo" parameter on wp_get_achives to 0/false. That way the method will return an array of data and leave it up to your to loop over it and print it out. Edit My mistake, it returns it just as a string, which means this is going to be quite tricky. Depends on how much styling you need to apply.

iAn
i specifically need the span class on the number output in the php string. Month (number)
HollerTrain
the example shows <ul> tag just replace it with a <span> tag
Phill Pafford
The above will style the parentheses as well as the number within. If you just want to style the number, then you are going to have to either: follow the "Hard" option and parse the return string from wp_get_archives using some reg-ex hacks, or write your own template function to generate this how you want it.
iAn
ah yes i am retarded. well, mentally challenged. this worked perfectly!
HollerTrain