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?

Kyle Hotchkiss
147
Commenti
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)

A'laa Nassar
29
25 ott 2017 14:10:42
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

Wyck
18K
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');
}
?>

Andres Yanez
396
24 nov 2011 03:56:06
Domande correlate
3
risposte
4
risposte
4
risposte