Ver Mensaje Individual
  #5 (permalink)  
Antiguo 18/03/2015, 15:23
Avatar de zanguanga
zanguanga
Moderadora
 
Fecha de Ingreso: julio-2009
Ubicación: España
Mensajes: 1.686
Antigüedad: 14 años, 9 meses
Puntos: 429
Respuesta: Agrupar fechas de un listado

Hay un plugin que lo hace: https://wordpress.org/plugins/simple-yearly-archive/

También puedes probar tu propio código. Aquí he encontrado este:
Código PHP:
Ver original
  1. <?php
  2. // get years that have posts
  3. $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" );
  4.  
  5. foreach ( $years as $year ) {
  6.     // get posts for each year
  7.     $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 . "'" );
  8.  
  9.     echo '<h2>' . $year->year . '</h2><ul>';
  10.     foreach ( $posts_this_year as $post ) {
  11.         echo '<li>' . $post->post_title . '</li>';
  12.     }
  13.     echo '</ul>';
  14. }
  15. ?>
__________________
Mi blog personal | Mi G+