Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Show all child pages of current page WordPress

  • SOLVED

Hello, I would like to show all child pages of the current page.

For each of these child pages, I would like to show:

- The child page's title (with link)
- The featured image of the child page (with link)
- The custom field of the child page 'role'

I would like to show them in the order of 'date'

I will be adding this code to my page template.

Thank you

Answers (1)

2014-05-08

Arnav Joy answers:

please try this



<?php

$current_page = get_the_ID();
$pages = get_pages( array( 'sort_order' => 'DESC', 'sort_column' => 'ID', 'child_of' => $current_page ) );

if( !empty( $pages ) ){
echo '<ul>';
foreach ( $pages as $page ) {
echo '<li>';
?>
<h3><a href="<?php echo get_permalink($page->ID);?>"><?php echo get_the_title($page->ID);?></a></h3>
<?php if ( has_post_thumbnail($page->ID)) : ?>
<a href="<?php echo get_permalink($page->ID); ?>" >
<?php echo get_the_post_thumbnail($page->ID); ?>
</a>
<?php endif; ?>
<span>Role<?php echo get_post_meta( $page->ID,'role',true );?></span>
<?php
echo '</li>';
}

echo '</ul>';
}


Arnav Joy comments:

i have edited my answer above please check it now.


Ross Gosling comments:

Thank you Arnav, works great.