Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. // get years that have posts
  2. $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" );
  3.  
  4. foreach ( $years as $year ) {
  5. // get posts for each year
  6. $posts_this_year = $wpdb->get_results( "SELECT post_title FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' AND YEAR(post_date) = '" . $year->year . "'" );
  7.  
  8. echo '<h2>' . $year->year . '</h2><ul>';
  9. foreach ( $posts_this_year as $post ) {
  10. echo '<li>' . $post->post_title . '</li>';
  11. }
  12. echo '</ul>';
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement