¿Cómo mostrar las entradas mes a mes?

9 jul 2011, 04:48:24
Vistas: 22.4K
Votos: 1

¿Cómo se podría usar wp_query para mostrar entradas mes a mes, y que solo muestre el último año? ¿O es posible que algún método alternativo de wp_archive pueda manejar esto?

1
Comentarios

Consulta también mi respuesta aquí, es una función práctica que creé: https://wordpress.stackexchange.com/a/276929/10381

Luca Reghellin Luca Reghellin
15 ago 2017 12:01:21
Todas las respuestas a la pregunta 3
1

WordPress 3.7 introdujo la consulta date_query para mostrar publicaciones mes por mes:

$args = array(
    'date_query' => array(
        array(
            'month' => $month
        )
    )
);
$query = new WP_Query( $args );

Nota: $month se refiere al número del mes (1-12)

25 oct 2017 14:10:42
Comentarios

¡¡¡Solución perfecta!!!!.. Gracias por ahorrarme tiempo. :)

Raghav Raghav
17 jun 2020 09:28:38
0

Bueno, no es un truco sino una función. Puedes usar simplemente wp_get_archives

http://codex.wordpress.org/Function_Reference/wp_get_archives

Alternativamente puedes usar un wp_query con un formato de tiempo para contenido actual, por ejemplo,

//Diciembre
$query = new WP_Query( 'monthnum=12' );

http://codex.wordpress.org/Class_Reference/WP_Query#Time_Parameters

9 jul 2011 06:32:58
1

Prueba esto, debo aclarar que el código está basado en un fragmento que vi.

    <?php

$blogtime = date('Y');
$prev_limit_year = $blogtime - 1;
$prev_month = '';
$prev_year = '';

$args = array(
         'posts_per_page' => 20,
         'ignore_sticky_posts' => 1
);

$postsbymonth = new WP_Query($args);

while($postsbymonth->have_posts()) {

    $postsbymonth->the_post();

    if(get_the_time('F') != $prev_month || get_the_time('Y') != $prev_year && get_the_time('Y') == $prev_limit_year) {

                   echo "<h2>".get_the_time('F, Y')."</h2>\n\n";

        }

    ?>

        <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>

                <?php // tus otras etiquetas de plantilla ?>


    <?php

    $prev_month = get_the_time('F');
    $prev_year = get_the_time('Y');

}

        ?>
24 nov 2011 03:56:06
Comentarios

¿Puedes hacer que también muestre los meses con cero publicaciones?

davebowker davebowker
5 ago 2012 06:16:36