I am looking to add a top ten type list to my WP website.
I currently have the following but I need t开发者_如何学运维o be able to make it get posts from multiple category IDs, does anybody know how I would go about doing this?
Thanks in advance for your help.
<div>
<?php
$args=array(
'cat' => 75, // this is category ID
'orderby' => 'comment_count',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 10, // how much post you want to display
'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(); ?>
</div>
I've tested your code on a dev site of mine and it does what you are wanting; however, with WP_DEBUG set to true, I get an error indicating that the parameter caller_get_posts
is deprecated in 3.1. Depending on your PHP setup and server config, this could cause problems for you. I would suggest making the following change:
<div>
<?php
$args=array(
'cat' => 75, // this is category ID
'orderby' => 'comment_count',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 10, // how much post you want to display
'ignore_sticky_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(); ?>
</div>
With the only change being substituting ignore_sticky_posts
for caller_get_posts
.
精彩评论