• Could someone point me in the right direction please?

    I am trying to get the content of 4 particular pages on the home page by mentioning their ID’s:

    <div class="getPages"> <?php
      $home_page_post_id = 674;
      $home_page_post = get_post( $home_page_post_id, ARRAY_A );
      $content_home = $home_page_post['post_content'];
      echo $content_home; ?> </div>

    The div is multiplied 4 times but I actually need to get all the child pages of the About page and not make the same div 4 times.

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • try to work with get_pages() and the ‘child_of’ (and ‘parent’) parameter:

    http://codex.wordpress.org/Function_Reference/get_pages

    Thread Starter Chris Demetriad

    (@carlozdre)

    Thank you.

    I was able to get the job done after alchymyth’s suggestion, for whoever needs a similar solution, there you go:

    <?php
    $home_page_post_id = CHANGE_THIS_TO_YOUR_ID;
    // example: $home_page_post_id = 56;
    $rand_posts = get_pages( array( 'child_of' => $home_page_post_id), 'numberposts=4&orderby=rand');
    foreach( $rand_posts as $post ) : setup_postdata($post); ?>
    <span class="getPages">
    
    <div> <a href="<?php the_permalink(); ?>">
    <?php $blogimageurl = wp_get_attachment_url(get_post_thumbnail_id());
    $imagepath = $blogimageurl;
    echo '<img src="'.get_bloginfo('template_url').'/functions/thumb.php?src='.$imagepath.'&h=134&w=212&zc=1"/>'; ?> </a> </div>
    
    <h1><?php the_title();?></h1>
    <?php echo excerpt(20); ?>
    </span>
     <?php endforeach; ?>

    The above code displays the content of the children pages on whatever page you’ll put it in, in my case maximum 4 entries, with title and some content and also the featured image on top.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get the content of child pages on the home page’ is closed to new replies.