Wordpress Show list of Child pages and Featured Image on Current Page

36 posts
  • Collector Level 4
  • United States
  • 5 Years of Membership
  • Exclusive Author
danyno45
says
Hello everyone, Its been a week i am reading and trying every code that i have found on the net to “Show list of Child pages and Featured Image on Current Page” i really tried everything and nothing seems to work. I am using the Avada theme. Please help thank you in advance
Thats my last try :(
    <?php
    $child_pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = ".$post->ID." AND post_type = 'page' ORDER BY menu_order", 'OBJECT'); ?>
    <?php if ( $child_pages ) : foreach ( $child_pages as $pageChild ) : setup_postdata( $pageChild ); ?>
    <div class="child-thumb">
    <?php echo get_the_post_thumbnail($pageChild->ID, 'thumbnail'); ?>
    <a href="<?php echo get_permalink($pageChild->ID); ?>" rel="bookmark" title="<?php echo $pageChild->post_title; ?>"><?php echo $pageChild->post_title; ?></a>
    </div>
    <?php endforeach; endif;
    ?>
41 posts
  • Collector Level 2
  • United Kingdom
  • Exclusive Author
  • 2 Years of Membership
Makins
says

You’ll need to run with this, but it should help point you in the right direction. Put this in the loop for your page (in page.php):

    $page_query = new WP_Query();
    $all_pages = $page_query->query( array('post_type' => 'page') );

    $page_children = get_page_children( get_the_id(), $all_pages );
    $current_page = $page_children[0];

    echo '<ul>';
    echo '<li>' . get_the_post_thumbnail( $current_page->ID, 'thumbnail' ) . $current_page->post_title . '</li>';
    echo '</ul>';
36 posts
  • Collector Level 4
  • United States
  • 5 Years of Membership
  • Exclusive Author
danyno45
says

You’ll need to run with this, but it should help point you in the right direction. Put this in the loop for your page (in page.php):
    $page_query = new WP_Query();
    $all_pages = $page_query->query( array('post_type' => 'page') );

    $page_children = get_page_children( get_the_id(), $all_pages );
    $current_page = $page_children[0];

    echo '<ul>';
    echo '<li>' . get_the_post_thumbnail( $current_page->ID, 'thumbnail' ) . $current_page->post_title . '</li>';
    echo '</ul>';

Thank you so much for your reply… Could you please reply with the whole block code i need to add to page.php. Thanks

41 posts
  • Collector Level 2
  • United Kingdom
  • Exclusive Author
  • 2 Years of Membership
Makins
says

That code on it’s own should work, provided you paste it into the loop. I don’t know what’s in Avada’s page.php, so I can’t give you any more detail than that I’m afraid.

36 posts
  • Collector Level 4
  • United States
  • 5 Years of Membership
  • Exclusive Author
danyno45
says

It worked, thanks a lotttt Makins :)

by
by
by
by
by
by