36 posts
  • United States
  • Bought between 100 and 499 items
  • Has been a member for 4-5 years
  • 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;
    ?>
38 posts
  • United Kingdom
  • Exclusive Author
  • Bought between 1 and 9 items
  • Has been a member for 1-2 years
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
  • United States
  • Bought between 100 and 499 items
  • Has been a member for 4-5 years
  • 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

38 posts
  • United Kingdom
  • Exclusive Author
  • Bought between 1 and 9 items
  • Has been a member for 1-2 years
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
  • United States
  • Bought between 100 and 499 items
  • Has been a member for 4-5 years
  • Exclusive Author
danyno45 says

It worked, thanks a lotttt Makins :)

by
by
by
by
by
by