isChildOf working, but also on wrong children

I’m using isChildOf to check for something. It -seems- to be working, but it’s working for another parent page as well as the one I’m specifying. It does what I want when I’m on a child of the ‘news’ parent, and unfortunately on children of another parent page called “work.”

<?php if($page->isChildOf('news') or (param('tag'))): ?>

  //do something only if user is viewing a child of news, or there is a tag parameter active in the URL.  

  <?php else: ?>

  //do something in every other case

<?php endif ?>

Any ideas?

I fixed it by using isDescendantOf() instead.

<?php if($page->isDescendantOf('news') or (param('tag'))): ?>

Thanks! Had the same issue, isDescendantOf() fixed it.

1 Like