Reputation: 31
Consider:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts( array('category_name' => 'parent','posts_per_page'=>'3','paged' => $paged));
if(have_posts()):
while(have_posts()):
?>
<?php the_post(); ?>
<?php endwhile; ?>
<?php else: ?>
<div class="entry"> Sorry, no posts found. Please try the
<a href="<?php bloginfo('home'); ?>">Homepage →</a>
</div>
<?php endif; ?>
This code only displays the parent post of the page, but I want to display the pages which are under the parent category: For example: ParentPage -> ChildPage. I need to display the child page...
Upvotes: 2
Views: 156
Reputation: 31
<?php
$args = array( 'category_name' => 'child_category' );
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
the_content();
}
/* Restore original Post Data */
wp_reset_postdata();
} else {
// no posts found
}
?>
Thank you... This one solved my Problem. :)
Upvotes: 0
Reputation: 614
You will have to query the child of that parent categories, by get_categories
$child_categories = get_categories( array(
'orderby' => 'name',
'parent' => 0
) );
replace 0 with the id of your parent category, Now use the array of child category to get the data, use WP_Query instead f query_posts
$query = new WP_Query( array( 'cat' => '2,6,17,38' ) );
Upvotes: 0