WordPress query to list archives

<?php

$archiveQry= “SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts

FROM $wpdb->posts  GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC “;

$archivesData = $wpdb->get_results($archiveQry); foreach($archivesData as $key=>$archive) {  ?>

<a href=””><?php echo date(“M”, mktime(0, 0, 0,$archive->month, 1, $archive->year));  ?>

<?php echo $archive->year  ?> </a>

<?php } ?>

Share

Leave a Reply

Your email address will not be published. Required fields are marked *