• Hi,

    Firstly, I am trying to format my Archives sidebar in a certain way, so that it takes the format of the one in this example:

    http://bldgblog.blogspot.co.uk/2013_03_01_bldgblog_archive.html

    The second thing it must do is show only the months where posts from a certain category- blog (as I use posts for other purposes in the site) exist.

    I did achieve the appearance using the following code:

    <?php
    $year_prev = null;
    	$months = $wpdb->get_results(
    		"SELECT DISTINCT MONTH( post_date ) AS month ,
    		YEAR( post_date ) AS year,
    		COUNT( id ) as post_count FROM $wpdb->posts
    		WHERE post_status = 'publish' and post_date <= now( )
    		and post_type = 'post'
    		GROUP BY month , year
    		ORDER BY post_date DESC"
    						);
    	foreach($months as $month) :
    		$year_current = $month->year;
    		if ($year_current != $year_prev){
    			if ($year_prev != null){?>
    			</ul>
    			<?php } ?>
    		<h4><?php echo $month->year; ?></h4>
    		<ul class="archive-list">
    		<?php } ?>

    At this point however, months appear where I have no posts from the category – blog, so that when you click on them, no posts apear , whch is not ideal.

    Any help would be gratefully recieved!

  • The topic ‘Formatting my archives sidebar in a specific way’ is closed to new replies.