Hi there,
I have 8 parent categories but all posts are under the child categories. I want to display the latest 5 posts per child categories in that parent category page.
Parent Category 1 (http://example.com/category/parent-category-1/)
-- Sub Category 1
(show 5 posts here)
-- Sub Category 2
(show 5 posts here)
-- Sub Category 3
(show 5 posts here)
-- Sub Category 4
(show 5 posts here)
-- Sub Category 5
(show 5 posts here)
Parent Category 2
-- Sub Category 1
(show 5 posts here)
-- Sub Category 2
(show 5 posts here)
-- Sub Category 3
(show 5 posts here)
-- Sub Category 4
(show 5 posts here)
-- Sub Category 5
(show 5 posts here)
Parent Category 3
same as above
What I have is this:
<?php
//for each category, show 1 post
$cat_args=array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories=get_categories($cat_args);
foreach($categories as $category) {
$args=array(
'showposts' => 1,
'category__in' => array($category->term_id),
'caller_get_posts'=>1
);
$posts=get_posts($args);
if ($posts) {
echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
foreach($posts as $post) {
setup_postdata($post); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
} // foreach($posts
} // if ($posts
} // foreach($categories
?>
But this code displays posts on every single parent and child categories. Can anyone help me to only display posts of child categories of the parent category it is under.
Many Thanks in advance.