How to query pages and return title, thumbnails, excerpts and custom field data

I have set up child pages with each having its own category name.  I have a main page that I want to pull in the thumbnail (featured image), title, excerpt, and custom field data (not sure what this will be yet) for each of these child pages. Please note that these are not posts but pages.

I have created a custom page template for the main page but need help on how to add in the query for the child pages data.

Who is Participating?
gr8gonzoConnect With a Mentor ConsultantCommented:
First, if you're not familiar with objects in PHP, you might want to read up on them a bit. Wordpress's API works with objects a lot.

Next, make sure you have the WP Function Reference handy - it will save your skin when you're building out WP customizations:

Next, you should understand the difference between pages and posts. Pages are more "static" content while "posts" are more dynamic. For example, my blog has an "About" page that stays at a specific URL and is rarely updated and then the blog has posts which are technical write-ups that I add all the time.

Finally, the functions you'll probably want to use are:

You're already using get_pages() but from what you've written, it sounds like you don't realize all of the other information that is coming back and is already available (e.g. each object in $mypages has a "post_excerpt" containing a preview of the content. If you go to the get_pages link above and scroll down to the Return section, you can see all of the data that is available to you when you work with a page object.

The thumbnails HTML can be retrieved on a per-page basis using this code:
echo get_the_post_thumbnail($page->ID, 'thumbnail');
That's extremely vague. Remember, we have no idea of what your site / code currently looks like. The most information I can infer is that you're working with a WP site.

That said, I would really recommend just going into the database using a GUI tool like HeidiSQL and viewing the tables and data, and then test out your queries there.
dukiejc99Author Commented:
Yes, I'm working with a WP site.  Sorry, I'll try to explain it in more details.  I'm afraid i'm not familiar with working with database as you suggested.

I've created a child theme and what i'm trying to do is to have a main page featuring a list of contributors.  I went and created a child page for each of the contributor.  I've also enabled categories and excerpts on the pages hoping i'll be able to use them somehow.  

On my main page, i'm trying to figure out how to be able to pull in from these child pages, the title, thumbnail (added as featured image), excerpts and possibly data from a custom field.  I'm not sure if this is even possible to do it like pulling in posts.  

Here is what I have so far below but it doesn't pull in what I need but just the full content of the page.

<?php get_header(); ?>

<div id="content-area" class="clearfix<?php if ( $fullwidth ) echo ' fullwidth'; ?>">
      <div id="left-area">
            <?php get_template_part('includes/breadcrumbs', 'page'); ?>

      $mypages = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'post_date', 'sort_order' => 'desc' ) );

      foreach( $mypages as $page ) {            
            $content = $page->post_content;
            if ( ! $content ) // Check for empty page

            $content = apply_filters( 'the_content', $content );
            <h2><a href="<?php echo get_page_link( $page->ID ); ?>"><?php echo $page->post_title; ?></a></h2>
            <div class="entry"><?php echo $content; ?></div>

      </div> <!-- end #left-area -->

      <?php if ( ! $fullwidth ) get_sidebar(); ?>
</div>       <!-- end #content-area -->

<?php get_footer(); ?>
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.