Bikash Gurung Bikash Gurung - 26 days ago 11
PHP Question

Display a post of subcategories in WordPress?

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 &rarr;</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...

Answer
<?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. :)

Comments