wordpress - How to return results from single category in this query? -
how can return latest post category 84 in query?
<?php /*$args = array('post_type'=>'post', 'posts_per_page'=>'10', 'post_no_in'=>$do_not_duplicate);*/ $args = array('post_type'=>'post', 'post_no_in'=>$do_not_duplicate); $query = new wp_query($args); query_posts("cat=84&showposts=1&orderby=desc"); if($query->have_posts()){ while(have_posts()) : the_post(); /*$do_not_duplicate[] = get_the_id();*/ ?> <div> <?php the_post_thumbnail(); ?> <div class="instruction"> <div class="home_title">most read</div> <div class="home_title_desc"><h3><a href="<?php the_permalink(); ?>"><?php echo the_title(); ?></a></h3></div> </div> </div> <?php endwhile; ?> <?php } ?>
i've tried 'cat' => 84, in array, no go. can show me how return results category 84? thanks
this code messy , attemps run 2 queries in row; 1 of them using query_posts()
never idea (see here explanation).
here's query rewritten you, getting latest post category 84 requested:
$args = array( 'post_type' => 'post', 'category__in' => 84, 'order' => 'desc', 'posts_per_page' => 1, ); $query = new wp_query($args); if($query->have_posts()){ while(have_posts()){ the_post(); // stuff here... } }
for information on each of these arguments do, see wp_query documentation. in particular, it's posts_per_page
argument tells wordpress return 1 post you.
i've left out 'post_no_in'=>$do_not_duplicate
original code because i'm not sure doing, if want ask feel free, or can find appropriate argument in wp_query documentation , add $args
array above.
Comments
Post a Comment