Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Test if page has children
#1
Can anyone suggest a PHP snippet that will test if the current page has children?

My aim is to make a section of my template conditional on the page having children:
if has children
...some content
else
...some other content

Thanks.
Reply
#2
The below works, but would be interested to hear if there's a better way. I'm a PHP beginner.

Code:
<?php
$kids = getChildren(return_page_slug());
if (!empty($kids)) {
    
...do some stuff

}
?>
Reply
#3
Code:
<?php if (count(getChildren(return_page_slug())) > 0) { ?>
...
<?php } else { ?>
...
<?php } ?>

(for GS 3.1+)
Reply
#4
Thanks Carlos, that's tidier.
Reply
#5
Your way is also valid, I hadn't seen your post. :-)
Reply




Users browsing this thread: 1 Guest(s)