Strangely enough WordPress has no function for checking whether a page has children/subpages. This has to be checked using a somewhat more cumbersome method as highlighted below:
$children = get_pages('child_of='.$post->ID);?>
if( count( $children ) != 0 ) { // Has Children }
else { // No children }
OR
$children = wp_list_pages('&child_of='.$post->ID.'&echo=0');
if($children) {
// This page has subpages
}
If anyone knows of a better way to do this I’d be interested to know. Until then, this is probably the best way to check whether a page has children or subpages.
Related posts:

Web professional in Malta, Europe. Focusing on building visually stunning websites that are easy to maintain, usually using WordPress as the CMS. Web developing since 1995, loving WordPress for more than 5 years.
One Comment
Got something to say? Feel free, I want to hear from you! Leave a Comment
Trackbacks for this post