0

I have a page like this

phyiscs
---mechanics
---statics
---Universe

chemistry
---Reaction
---Equilibrium

biology
---Human body
---Polination

I want to display the chilren of page physics,chemistry , biology like this

<div class="phy-child">
   <h1>Mechanics</h1>
   <h1>statics</h1>
   <h1>Universe</h1>
</div>

<div class="chem-child">
   <h1>Reaction</h1>
   <h1>Equilibrium</h1>
</div>

and so for biology

I tried using wordpress query but don't know where should i insert physics etc..

<?php

$args = array(
    'post_type'      => 'page',
    'posts_per_page' => -1,
    'depth'          =>  2,
    'sort_column'  => 'post_name',
    'post_parent'    => $post->ID,
    'order'          => 'ASC',
    'orderby'        => 'menu_order'
 );


$parent = new WP_Query( $args );

if ( $parent->have_posts() ) : ?>

    <?php while ( $parent->have_posts() ) : $parent->the_post(); ?>

        <div id="parent-<?php the_ID(); ?>" class="parent-page">

            <h1><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>

        </div>

    <?php endwhile; ?>

<?php endif; wp_reset_query(); ?>

Is it possible to do ? Thanks

0

You need to pur div container before while loop. Here you go. Here is the modified code and container will have parent page slug class.

<?php

$args = array(
    'post_type'      => 'page',
    'posts_per_page' => -1,
    'depth'          =>  2,
    'sort_column'  => 'post_name',
    'post_parent'    => $post->ID,
    'order'          => 'ASC',
    'orderby'        => 'menu_order'
 );


$parent = new WP_Query( $args );

if ( $parent->have_posts() ) : ?>

  <div id="parent-<?php the_ID(); ?>" class="<?php echo $post->post_name; ?>-page">

    <?php while ( $parent->have_posts() ) : $parent->the_post(); ?>

        <h1><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>

    <?php endwhile; ?>

  </div>

<?php endif; wp_reset_query(); ?>
|improve this answer|||||
  • Hey I want to display it in archives page like that . But where do i show the children post using title of parents page like chemistry etc. – user80946 Sep 21 '15 at 3:03
  • Not quite sure what exactly do you want. You said, need to show children of page. Please explain more. – Robert hue Sep 24 '15 at 5:08
  • Yes i want to show children of a page but on archives-notes.php ...I want to show children of physics using the name phyiscs . – user80946 Sep 25 '15 at 2:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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