WordPress – archive page: list posts by year olatechproMarch 26, 20233 Views I need to get something like this: 2014 post 1 post 2 post 3 post 4 2013 post 1 post 2 post 3 How can I achieve this? Post Views: 3 Related postsGet rid of this Strict Standards warningWooCommerce: get_current_screen not working with multi languageCan’t login on WordPressForce HTTPS using .htaccess – stuck in redirect loopWordPress: Ajax not working to insert, query and result dataHow Can I pass an image file to wp_handle_upload?
Here is what you need: $yearly = new WP_Query(array('posts_per_page' => -1)); $prev_year = null; if( $yearly->have_posts() ) : while( $yearly->have_posts() ) : $yearly->the_post(); $this_year = get_the_date('Y'); if ($prev_year != $this_year) { if (!is_null($prev_year)) { echo '</ul>'; } echo '<h3>' . $this_year . '</h3>'; echo '<ul>'; } echo '<li>'; echo '</li>'; $prev_year = $this_year; endwhile; echo '</ul>'; endif; Please take a look at the documentation as well: http://codex.wordpress.org/Class_Reference/WP_Query Log in to Reply
Here is what you need:
Please take a look at the documentation as well: http://codex.wordpress.org/Class_Reference/WP_Query