Come visualizzare i post mese per mese?

9 lug 2011, 04:48:24
Visualizzazioni: 22.4K
Voti: 1

Come si potrebbe utilizzare wp-query per mostrare i post mese per mese, limitandosi solo all'ultimo anno? Oppure è possibile gestire questo tramite qualche modifica alle funzioni wp_archive?

1
Commenti

Vedi anche la mia risposta qui, è una funzione utile che ho creato: https://wordpress.stackexchange.com/a/276929/10381

Luca Reghellin Luca Reghellin
15 ago 2017 12:01:21
Tutte le risposte alla domanda 3
1

WordPress 3.7 ha introdotto la date_query per visualizzare gli articoli mese per mese:

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

Nota: $month si riferisce al numero del mese (1-12)

25 ott 2017 14:10:42
Commenti

Soluzione perfetta!!!!.. Grazie per avermi fatto risparmiare tempo. :)

Raghav Raghav
17 giu 2020 09:28:38
0

Beh, non è un hack ma una funzione. Puoi semplicemente usare wp_get_archives

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

In alternativa puoi usare una wp_query con un formato temporale per i contenuti attuali, ad esempio:

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

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

9 lug 2011 06:32:58
1

Prova questo, dovrei chiarire che il codice si basa su uno snippet che ho visto.

    <?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 // i tuoi altri tag template ?>


    <?php

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

}

        ?>
24 nov 2011 03:56:06
Commenti

Puoi fare in modo che vengano stampati anche i mesi con zero post?

davebowker davebowker
5 ago 2012 06:16:36