i have a category named news and many subcategories inside it. What i wanna do is to get only 1 posts(newest) from each of those sub categories(including category title, post title, attachment image). Is there any suggestions friends??
+1
A:
<?php
$news_cat_ID = get_cat_ID('News');
$news_cats = get_categories("parent=$news_cat_ID");
$news_query = new WP_Query();
foreach ($news_cats as $news_cat):
?>
<h2><?php echo esc_html($news_cat->name); ?></h2>
<?php $news_query->query('posts_per_page=1&cat=' . $news_cat->term_id); ?>
<?php if ($news_query->have_posts()): $news_query->the_post(); ?>
<div class="post">
<?php the_title(); ?>
<!-- do whatever you else you want that you can do in a normal loop -->
</div>
<?php endif; ?>
<?php endforeach; ?>
TheDeadMedic
2010-07-17 15:10:18
thank u THEDeadMedic. it worked, and can you help me another one.(extendign the same code)how do i show only those post who has image attachment and ordered by date
sonill
2010-07-18 05:37:42