Based on the code posted by krusch, here’s what I ended up with:
<?php
$pages = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=desc&parent='.$post->ID);
foreach($pages as $page) {
?>
<div class="section" id="<?php echo $page->post_name; ?>">
<h4><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a></h4>
<?php echo apply_filters('the_content', $page->post_content); ?>
</div>
<?php } ?>
The code from krusch stopped after 2 items, so I removed that logic.
I also changed the class on the wrapping div to “section” rather than “feature_product” since it made more sense in the context of my particular usage (but it’s semantically generic enough for general use). I also added an id to the wrapping div – this id is based on the ‘URL slug’ by using ‘$page->post_name’.
Also notice that I changed the H2 to an H4 (only because it made sense in the context of my usage), but please also notice that the code from krusch wraps an anchor (‘a’) element around the H2 which is invalid HTML, so I instead wrapped the H2 (H4 in my case) around the anchor.
As krusch suggests, you can also call the content which I originally did using just $page->post_content
. That worked, but it needed formatting, so I ran it through the apply_filters()
function like so: apply_filters(‘the_content’, $page->post_content);
Hope this helps. And to answer mortocks’ question – yes, this code is added to page.php