I am trying to check if a parent Page has children. If it has children I would like to echo the children as a bulleted list with links to each child (basically a menu).
Right now I have the following code in loop-page.php and it checks if the Page has any children and returns an array with the children. I use an if statement to check if the number is greater than 0.
$children = get_pages('child_of='.$post->ID.'&parent='.$post->ID);
if (count($children)) {
// Echo children as a bulleted list of links
}
This part seems to work.
My question is how do I echo through the children as a bulleted list of links? Like the example below.
Let's say "Services" is the parent page and its children pages are "Grass Cutting", "Water Gardens", and "Landscaping".
count($children) would return 3 for the "Services" page since it has 3 children. Now it should echo them as so:
<ul>
<li><a href="#">Grass Cutting</a></li>
<li><a href="#">Water Gardens</a></li>
<li><a href="#">Landscaping</a></li>
</ul>
a href= should be the link to the page.