Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Hi I would like to display all child pages from all parents pages. Not from specific parent! and I would like to display them as random.

The code I used currently :

$posts=get_posts('child_of='.$post>ID.'paged=2&posts_per_page=1&sort_column=post_date &sort_order=desc&showposts=3$orderby=rand&post_type=page');

Now if I use random as orderby then it shows all parents and child pages. But what I'm doing now use orderby=post_date and limit the number of posts as 3 so now i'm getting 3 child pages which I wanted, but I add more page as child then it won't appear, because I'm not using random.

Haven't found any template tag for child page display.

The full code is follows:

<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?/*php $post=query_posts('showposts=3'); */?> 

<?php $post=query_posts('post_type=page&orderby=rand&posts_per_page=3'); ?>

<?/*php $posts =get_posts('paged=2&posts_per_page=1
&orderby=rand&showposts=3&post_type=page'); foreach ($posts as $post) : start_wp(); */?>

<?php $posts = get_posts('child_of='.$post->ID.'
  $paged=2&posts_per_page=1&sort_column=post_date &sort_order=desc&showposts=3
  $orderby=post_date&post_type=page'); // important

foreach ($posts as $post) : start_wp(); ?>

    <?php static $count1 = 0; if ($count1 == "2") { ?>
    <div id="lastcolumn">
    <div id="entry">
   <a href="<?php the_permalink() ?>"><img src="<?php get_post_thumbnail(); ?>" /></a>
   <div id="entry-text">
   <?php $entry = get_post_meta($post->ID, 'additional_text', true); ?>

   <h1><?php the_title(); ?> /&nbsp</h1><p><?php echo $entry; ?></p>
 </div>
</div>
</div>


  <?php } elseif ($count1 == "3") { break; } else { ?>
  <div id="column">
  <div id="entry">
  <a href="<?php the_permalink() ?>"><img src="<?php get_post_thumbnail(); ?>" /></a>
  <div id="entry-text">
  <?php $entry = get_post_meta($post->ID, 'additional_text', true); ?>
  <h1><?php the_title(); ?> /&nbsp</h1><p><?php echo $entry; ?></p>
  </div>
  </div>
 </div>
<?php $count1++; } ?>
<?php endforeach; ?>

Any help or clue wiill be great favor.

Thanks in advance.

share|improve this question
add comment

1 Answer 1

Here's a random thought. query for ALL pages, but exclude the parents. Something like this maybe?

query_posts( array( 'post__not_in' => array( 2, 5, 12, 14, 20 ) , 'post_type' => 'page', 'orderby' => 'rand' , 'posts_per_page' => '3' ) );
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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