How to add a span class in the following php?

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?

Read More

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.

Related posts

Leave a Reply

1 comment

  1. 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.