issue with checking whether a page has children
-
Ahoy!
I’m trying to display portions of my sidebar differently depending on whether a page has children. If it does, it displays the children in a list that expands when you click the page name, but isn’t a link. Else, it is a link. Currently, it’s not working. Here’s the code:
<?php $pages = get_pages(array('parent' => 0)); foreach( (array) $pages as $page) { $children = get_pages(array('child_of='.$page->ID)); if( count( $children ) != 0 ) { echo '<h2 class="menuheader">' . get_the_title($page->ID) . '</h2>'; echo '<div class="menucontent"><ul>'; wp_list_pages('child_of=' . $page->ID . '&title_li='); echo '</ul></div>'; } else { echo '<a href="' . get_page_link($page->ID) . '"><h2 class="menuheader">' . get_the_title($page->ID) . '</h2></a>'; } } ?>Currently, the sidebar treats everything as a clickable menu, even pages without children. Not sure why. I searched the forums, codex, and google, to no avail. Any help or insight would be greatly appreciated, thank you.
The topic ‘issue with checking whether a page has children’ is closed to new replies.