WordPress.org

Support

Support » Plugins and Hacks » Random page children

Random page children

  • Hi!

    I’m struggling to make a loop where, let’s say 4, children of a certain page ID is shown at a footer.

    I can make the loop with posts, but cannot figure out how to archive this functionality with pages…

    The code working for posts, looks like this;

    <?php
    $querystr = "SELECT * FROM (SELECT wposts.* FROM $wpdb->posts wposts WHERE wposts.post_status = 'publish' ORDER BY rand()) as y limit 4 ";
    $pageposts = $wpdb->get_results($querystr, OBJECT);
    
    ?>
     <?php if ($pageposts): ?>
      <?php foreach ($pageposts as $post): ?>
        <?php //setup_postdata($post); ?>
    
          <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></li>
    
        <?php endforeach; ?>
     <?php endif; ?>

    Any help or guidance will be appreciated!

    Thanks!

Viewing 1 replies (of 1 total)
  • Okay, I almost got it;

    <?php
    $rand_module = get_posts('static=true&child_of=37&number=2&orderby=rand');
    foreach( $rand_module as $post ) :
    ?>
    DO STUFF
    <?php endforeach; ?>

    But somehow the number=2 doesn’t work. The function gives me ALL of the children in random order. Anyone know how to limit this?

    Thanks…

Viewing 1 replies (of 1 total)
  • The topic ‘Random page children’ is closed to new replies.
Skip to toolbar