I’ve tried to echo excerpts in wp_list_pages
with the code below. It works, but only for one of the child pages. How would I echo the excerpt and title for each child page?
<?php
$children = wp_list_pages('title_li=&depth=1&child_of='.$post->ID.'&echo=0');
if ($children) { ?>
<h2>
<?php echo $children; ?>
<?php the_excerpt(); ?>
</h2>
<?php } ?>
If you want to make use of all the nifty filters for the title and excerpt/content (and why would you not want that?) you should loop through a custom query instead of using
get_pages
and the pages’ plain contents:wp_list_pages()
is for displaying a list of pages. It looks like you want to do more with it.Instead you should use
get_pages()
with returns an array of data about the pages which means you have much more flexibility with it. Here’s some sample code:You can’t do this the way you are attempting. All of the markup is generated by
wp_list_pages()
. You can’t “insert” content like that.You can apply a callback to the
wp_list_pages
hook but you’d need some tricky regex to do it.I think your best option is to pass a custom Walker to
wp_list_pages()
. Something like this: