• I’ve found the Flexi Pages widget, and the Collapsing Pages plugin that do most of what I want, but not all.

    Is there a way of showing only top level pages in the menu, and only show child pages when on the parent or related child pages?

    I really don’t want to use a plugin, and wanna know if there’s a wizard out there that can give me a bit of php to play with?

Viewing 7 replies - 1 through 7 (of 7 total)
  • This works in the WordPress Default theme’s wp-content/themes/default/sidebar.php file:

    <?php
    $output = wp_list_pages('echo=0&depth=1&title_li=<h2>Top Level Pages </h2>' );
    if (is_page( )) {
      $page = get_query_var('page_id');
      if ($post->post_parent) {
        $page = $post->post_parent;
      }
      $children=wp_list_pages( 'echo=0&child_of=' . $page . '&title_li=' );
      if ($children) {
        $output = wp_list_pages ('echo=0&child_of=' . $page . '&title_li=<h2>Child Pages</h2>');
      }
    }
    echo $output;
    ?>
    Thread Starter OthelloBloke

    (@othellobloke)

    Hey there…

    This works to a certain extent, but it also opens up the child pages on OTHER parent pages.. even if you’re not on them.

    Any ideas how to fix it?

    Sorry, I’m not seeing that problem.

    When I visit main page, all top level pages are listed in the sidebar.

    When I click on a top level page with no children, all top level pages are listed.

    When I click on a top level page with children, just the children pages are listed.

    When I click on a children page, just the children of that parent are listed.

    Thread Starter OthelloBloke

    (@othellobloke)

    When I click on a top level page with children… the child pages are listed for the page I click on… but also ALL the other child pages of other parents ??

    Disable all plugins, remove Widgets, change to the WordPress Default Theme, put that code in your sidebar.php in place of the wp_list_pages there.

    Haven’t heard back from you so guessing it may work now…

    If not maybe have to global $post in your case

    So after the <?php add global $post;

    Thread Starter OthelloBloke

    (@othellobloke)

    Nope it’s not working…

    The problem is this… I MUST use the following str_replace lines

    <?php
    global $post;
    $pages = wp_list_pages('echo=0&depth=1&title_li=&include=17&sort_column=menu_order' );
    if (is_page( )) {
      $pages = get_query_var('page_id');
      if ($post->post_parent) {
        $pages = $post->post_parent;
      }
      $child=wp_list_pages( 'echo=0&child_of=' . $page . '&title_li=&include=17&sort_column=menu_order' );
      if ($child) {
        $pages = wp_list_pages ('echo=0&child_of=' . $page . '&title_li=&include=17&sort_column=menu_order');
      }
    }
    $pages = str_replace('The Page Title', '<img src="https://www.domain.ca/wp-content/themes/ctj2b/images/logo.gif" border="0" />', $pages);
    $pages = str_replace('title="<img src="https://www.domain.ca/wp-content/themes/mctj2b/images/logo.gif" border="0" />"', 'title="The Page Title', $pages);
    echo $pages;
    ?>

    I MUST replace a page title text with an image… how can I make it work with these following two replacing statements?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Hide Child Pages Except When On Parent OR Related Child Pages’ is closed to new replies.