El siguiente código nos muestra los posts más populares (más comentados) dada una categoría:
<?php
$args=array(
'cat' => 3,
'orderby' => 'comment_count',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 6,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) { ?>
<ul>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
<?php }
wp_reset_query(); ?>
El código se inserta en el lugar en el que deseemos mostrar esta información.
Esta línea indica de que categoría deseamos mostrar los posts más populares. Reemplaza el 3 por el Id de la categoría que deseas mostrar.
'cat' => 3,
La siguiente línea indica cuantos posts deseas mostrar.
'posts_per_page' => 6,
Visto en dynamicwp.net » »