I'm trying to create a list of child pages of the current page only. But I also only want this list to show up on certain pages that have children, not all pages with children. So I decided to do this with the RunPHP plugin and put the code directly in the page content. I tried using this code from the codex in the page content:
The following example will generate a list only if there are child (Pages that designate the current page as a Parent) for the current Page:
<?php
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
if ($children) { ?>
<ul>
<?php echo $children; ?>
</ul>
<?php } ?>
That produced errors on the page. So I tried this, and it just gave me a hierarchy of all the pages and sub-pages that I have in the database:
<?php
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
if ($children) {
echo "<ul>";
echo $children;
echo "</ul>";
}
?>
Just like this does:
<ul>
<?php
wp_list_pages('title_li=&child_of='.$post->ID.''); ?>
</ul>
Is there a way to do show direct children on a page within the content? Maybe it would be more elegant to do it in the page php file in my theme, but I couldn't figure a way to confine it to only certain children.
Thanks