How to Hide Child Pages in Sidebar (3 posts)

  1. TerrySurl
    Posted 7 years ago #

    I'm learning PHP as I go along, so need some guidence. I'm using the theme "Paalam 1.1" which I've modified to suit my purposes. One modification defeats me, though. I want the sidebar to display only parent pages, with no child pages shown. The reason? Sidebar is growing too long, and I've not yet added all the child pages I intend. So how do I hide the child pages? Searching the forum and codex hasn't answered my question.

    Here are the possible relevant codes...

    From page.php:

    <div class="entry">
    <?php the_content(__('Continue Reading »')); ?>
    <?php wp_link_pages(); ?>
    <?php $sub_pages = wp_list_pages( 'sort_column=menu_order&depth=1&title_li=&echo=0&child_of=' . $id );?>
    <?php if ($sub_pages <> "" ){?>
    <p class="meta">This page has the following sub pages.</p>

      <?php echo $sub_pages; ?>

    <?php }?>

    And from sidebar.php:

      <?php wp_list_pages('title_li=' ); ?>

    Any help is greatly appreciated.


  2. TerrySurl
    Posted 7 years ago #

    Ah hah! I finally found the correct search terms to zero in on a solution to this using google.

    In sidebar.php the original code was:

      <?php wp_list_pages('title_li=' ); ?>

    I changed it to:

      <?php wp_list_pages('title_li=&depth=1' ); ?>

    Now only the parent pages show in the sidebar, just as I'd wished.


  3. Chrisber
    Posted 7 years ago #

    Aint it great when the answers are right there waiting for you? You might also want to read up on the include and exclude functions if you ever decide that you want to display some of those pages.

Topic Closed

This topic has been closed to new replies.

About this Topic