Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How do i show the latest post from a child category?

I have the category Photos, but I want to only show the latest post from the Child category "Paparazzi"

what do i add to the code below to do this

<?php 
query_posts('category_name=photos&showposts=1'); while(have_posts()) : the_post(); 
?>
share|improve this question
add comment

1 Answer

Just change your query to search for the category you want.

$qry = new WP_Query('category_name=paparazzi&showposts=1');
while($qry->have_posts()) : $qry->the_post(); 

That should most likely be all you need to do.

And please don't use query_posts. It alters the main query and can break things.

share|improve this answer
    
That didn't work, because paprazzi is a child category –  Mihad Aiko Apr 8 '13 at 21:51
    
That doesn't matter. The query doesn't care about the parent/child status, and I have tested that. You do need to use the slug and not the name though. –  s_ha_dum Apr 8 '13 at 22:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.