How can I organize/create an archive listing by Year and month

I thought this would be simpler using the basic widgets that WP provides but its not.

I need to create

Read More
  • 2012
    • Decemeber
    • November
  • 2011
    • December

The month items would be links to that archive.

Is this possible? I would prefer not to use a plugin but if thats the answer its ok.

Related posts

Leave a Reply

1 comment

  1. function archive_links_custom() {
        global $wpdb, $wp_locale;
        $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC";
        $arcresults = $wpdb->get_results($query);
        if ( $arcresults ) {
            $year = null;
            foreach ( (array) $arcresults as $arcresult ) {
                if($arcresult->year != $year) {
                    echo $arcresult->year;
                    $year = $arcresult->year;
                }
                $url = get_month_link( $arcresult->year, $arcresult->month );
                $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year);
                $after = ' ('.$arcresult->posts.')';
                echo '<a href="'.$url.'>'.$text.$after.'</a>';
            }
        }
    }
    

    This function should do what you want. Customize the markup in there the way you like