Forums

How to check if there are sub links? (3 posts)

  1. Spencer Hill
    Member
    Posted 2 years ago #

    Heya,
    So I'm working on a website where the breadcrumb lies immediately beneath the horizontal navigation. Problem is, when there are sub pages to the navigation they lay over my breadcrumb instead of pushing it down.
    Now, I'm not seeking advice on how to better write this nav, I just want to know if there is a way to use PHP to check if the current page you are on has any children. Does anyone know?

    Thanks!

  2. simplethemes
    Member
    Posted 2 years ago #

    If you're trying to detect sub-pages, you could try:

    <?php
        $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
        if ($children) { ?>
        // do something
      <?php } else { ?>
        // do something else
      <?php } ?>
  3. Spencer Hill
    Member
    Posted 2 years ago #

    Sweet, thanks for the reply. I ended up using PHP count before you replied:

    <?php
    $children = get_pages('child_of='.$post->ID);
    
    if( count( $children ) != 0 ) {
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.