• I am trying to find a nice snippet to display the excerpts of the current pages children.

    I found this bit of code but am not sure how to also incorporate the featured image (thumbnail) into it.

    <?php
    $pageChildren = get_pages(‘sort_column=menu_order&hierarchical=0&child_of=’.$post->ID);
    if ( $pageChildren ) {
    foreach ( $pageChildren as $pageChild ) {
    echo ‘<p>And the title is: ‘. $pageChild->post_title.'</p>’;
    if ($pageChild->post_excerpt){
    echo ‘<p>And the excerpt is: ‘.$pageChild->post_excerpt.'</p>’;
    }
    }
    }
    ?>

    Any suggestions would be great!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Chris

    (@lamordnt)

    OK, so I almost got this bad boy dialed in. Here is my current code:

    <?php
    $pageChildren = get_pages( array( ‘child_of’ => $post->ID, ‘sort_column’ => ‘menu_order’, ‘hierarchical’ => ‘0’ ) );
    if ( $pageChildren ) {
    foreach ( $pageChildren as $pageChild ) {
    echo ‘<h2>ID) . ‘” title=”‘ . $pageChild->post_title . ‘”>’. get_the_post_thumbnail($pageChild->ID).’</h2>’;
    if ($pageChild->post_excerpt){
    echo ‘<p>’.$pageChild->post_excerpt.'</p>’;
    }
    }
    }
    ?>

    But I want to also have it pull a custom field. So something like this:

    <?php
    $pageChildren = get_pages( array( ‘child_of’ => $post->ID, ‘sort_column’ => ‘menu_order’, ‘hierarchical’ => ‘0’ ) );
    if ( $pageChildren ) {
    foreach ( $pageChildren as $pageChild ) {
    echo ‘<h2>ID) . ‘” title=”‘ . $pageChild->post_title . ‘”>’. get_the_post_thumbnail($pageChild->ID).’</h2>’;
    if ($pageChild->post_excerpt){
    echo ‘<p>’.$pageChild->post_excerpt.'</p>’;
    }
    echo get_post_meta($post->ID, ‘website-link’, true);
    }
    }
    ?>

    But I cannot seem to get it to pull the custom field. Any suggestions?

    But I want to also have it pull a custom field.

    custom field of the current page or of each child page?

    Thread Starter Chris

    (@lamordnt)

    I would like to have it show a custom field of each child page.

    Thread Starter Chris

    (@lamordnt)

    Figured it out on my own for anyone trying to do this.

    The following will call the excerpt of the children of the current page, the thumbnail of the children of the current page and the custom field of the children of the current page.

    <?php
    $pageChildren =  get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'menu_order', 'hierarchical' => '0' ) );
    if ( $pageChildren ) {
      foreach ( $pageChildren as $pageChild ) {
        echo '<h2><a>ID) . '" title="' . $pageChild->post_title . '">'. get_the_post_thumbnail($pageChild->ID).'</a></h2>';
        if ($pageChild->post_excerpt){
          echo '<p>'.$pageChild->post_excerpt.'</p>';
        }
                    echo get_post_meta($pageChild->ID, 'custom-field-name', true);
      }
    }?>

    [Please post code or markup snippets between backticks or use the code button.]

    Hi Chris, can you doublecheck that code? Some of the syntax is wrong I believe in the echo?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Display Excerpts with Thumbnails for Child Pages of Current Page’ is closed to new replies.