WordPress.org

Ready to get started?Download WordPress

Forums

Get the content of child pages on the home page (3 posts)

  1. Chris Demetriad
    Member
    Posted 2 years ago #

    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.

  2. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    try to work with get_pages() and the 'child_of' (and 'parent') parameter:

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

  3. Chris Demetriad
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic