Support » Themes and Templates » Wrong display subpage on search results

  • Hi everyone!

    I have big problem. I use solution from . I want display subpages when user is on parent page. I use this code:

      $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
      $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
      if ($children) { ?>
      <?php echo $children; ?>
      <?php } ?>

    its works but when i use search and it shows me results but on this page are showing ALL subpages although this subpages shouldn’t show.


Viewing 1 replies (of 1 total)
  • ok, i know the post above is 7 months ago, but i thought this would be useful for anyone who got stuck on this problem.

    The simple solution to this is to use the Conditional Tag is_search(). Write a little PHP conditional statement before printing any pages, something like:

    <?php if (!is_search()) {echo $children;} ?>

    where $children contains the list of pages that will normally be displayed. This way, the list of pages will only be displayed if the currently showing page is not a search results page.

Viewing 1 replies (of 1 total)
  • The topic ‘Wrong display subpage on search results’ is closed to new replies.