Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I recently came across this cool tutorial on listing sibling pages. Below is the suggested code:

<?php
    //GET CHILD PAGES IF THERE ARE ANY
    $children = get_pages('child_of='.$post->ID);

    //GET PARENT PAGE IF THERE IS ONE
    $parent = $post->post_parent;

    //DO WE HAVE SIBLINGS?
    $siblings =  get_pages('child_of='.$parent);

    if( count($children) != 0) {
       $args = array(
         'depth' => 1,
         'title_li' => '',
         'child_of' => $post->ID
       );

    } elseif($parent != 0) {
        $args = array(
             'depth' => 1,
             'title_li' => '',
             'exclude' => $post->ID,
             'child_of' => $parent
           );
    }
    //Show pages if this page has more than one sibling 
    // and if it has children 
    if(count($siblings) > 1 && !is_null($args))   
    {?>
    <div class="widget subpages">
    <h3 class="widgettitle">Also in this Section</h3>
         <ul class="pages-list">
         <?php wp_list_pages($args);  ?>
         </ul>
     </div>
    <?php } ?>

I was wondering how can I can modify the above code snippet to include the featured image, post title, and permalink. I would like to imitate "related posts".

Looking forward to your input!

share|improve this question

1 Answer 1

up vote 0 down vote accepted

wp_list_pages only displays page title and link in list. Try following code to fetch page content and thumbnail.

<ul class="pages-list">
           <?php $our_pages = get_pages($args); ?>
           <?php if (!empty($our_pages)): ?>
            <?php foreach ($our_pages as $key => $page_item): ?>
              <li>
                <a href="<?php echo esc_url(get_permalink($page_item->ID)); ?>"><?php echo $page_item->post_title ; ?></a>
                <?php echo get_the_post_thumbnail($page_item->ID,'thumbnail'); ?>
              </li>
            <?php endforeach ?>
           <?php endif ?>
           </ul>
share|improve this answer
    
Thank you for your input! sending you a private message on nilambar.net :-) –  William Jun 6 at 6:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.