WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Displaying x random child pages (2 posts)

  1. Raisis
    Member
    Posted 2 years ago #

    Hi everbody,

    I'd like to display 3 random pages as a kind of excerpt ('this pages could be interesting for you'). It works that WordPress displays me one random child page.But I'd like to display 3 pages. This is my code:

    <?php
    					if (2 == $post->post_parent or 2 == $post->ID) {
    						$parent = 2;
    					} elseif (7 == $post->post_parent or 7 == $post->ID) {
    						$parent = 7;
    					} elseif (10 == $post->post_parent or 10 == $post->ID) {
    						$parent = 10;
    					}
    					$args=array(
    						'child_of' => $parent,
    						'number' => 3
    					);
    					$pages = get_pages($args);
    					shuffle($pages);
    					if ($pages) {
    						$pageids = array();
    						foreach ($pages as $page) {
    							$pageids[]= $page->ID;
    							$content = $page->post_excerpt;
    							$content = apply_filters( 'the_excerpt', $content );
    						}
    					}
    				?>

    The 'number' => 3 does not work and I have no idea why... Can somebody help me please?

    Greetings from Germany,
    Raisis

  2. Raisis
    Member
    Posted 2 years ago #

    Got it!

    <?php
    					if (2 == $post->post_parent or 2 == $post->ID) {
    						$parent = 2;
    					} elseif (7 == $post->post_parent or 7 == $post->ID) {
    						$parent = 7;
    					} elseif (10 == $post->post_parent or 10 == $post->ID) {
    						$parent = 10;
    					}
    
    					$count = 0;
    					$pages = get_pages('child_of=' . $parent);
    					shuffle($pages);
    					foreach($pages as $page) {
    						$content = $page->post_excerpt;
    						$content = apply_filters( 'the_excerpt', $content );
    						$count++;
    						if ( $count < 4) { ?>			
    
    MY LOOP
    				<?php
    						}
    					}
    				?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.