In questo articolo vedremo come mostrare i post più popolari del nostro sito in WordPress come una galleria di thumbnail cliccabili. Vediamo insieme i dettagli.
Aggiungete il seguente codice al file functions.php
:
<?php
function most_popular_post_thumbnail() {
$current_month = date('n');
if($current_month==1){ $last_month=12; }else{ $last_month=$current_month-1; }
$args = array(
'posts_per_page' => 4,
'monthnum' => $last_month,
'orderby' => 'comment_count',
);
?>
<h1>Post popolari</h1>
<div class="popular-posts">
<?php query_posts($args); ?>
<?php while (have_posts()) : the_post(); ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail( 'thumbnail' ); ?></a>
<?php endwhile; ?>
</div>
<?php
wp_reset_query();
}
?>
Quindi potete usare la funzione appena definita nel vostro tema:
<?php most_popular_post_thumbnail(); ?>