Contact

// Get years that have posts $years = $wpdb->get_results( "SELECT YEAR(post_date) AS year FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY year DESC" ); // For each year, do the following foreach ( $years as $year ) { // Get all posts for the year $posts_this_year = $wpdb->get_results( "SELECT ID, post_title FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' AND YEAR(post_date) = '" . $year->year . "'" ); // Display the year as a header echo '

' . $year->year . '

'; // Start an unorder list echo ''; // For each post for that year, do the following foreach ( $posts_this_year as $post ) { // Display the title as a hyperlinked list item echo '
  • ' . $post->post_title . '
  • '; } // End the unordered list echo ''; }