WordPress.org

Ready to get started?Download WordPress

Forums

Display Sub-Pages, Sub-Sub-Pages at all times - Please Help Me (3 posts)

  1. djmccabe
    Member
    Posted 5 years ago #

    Firstly "please" dont ask me to ask this on the wordpress forums, their forums never seem to end in a useful answer if you get an answer at all.

    Every time I come to do anything with the WordPress sidebar and displaying subpages, all hell brakes loose, when in fact what I am trying to do should be simple.

    Here is how the site works.

    In the header is the main navigation: About Us | Contracts | Portfolio

    When you click on one of these pages you get a submenu in the siderbar on the right, for example if you click on "Contracts" you see:

    - Completed
    -- Contract 1
    -- Contract 2
    -- Contract 3
    -In Progress
    -- Contract 4
    -- Contract 5
    -- Contract 6

    All good so far, if you click "Completed" or "In Progress" the menu again appaers as it is above, still good, however if you click on any of the individual contracts then you lose the rest of the options in the menu apart from those in that category, eg: if you click on "Contract 1" then the submenu only displays:

    -- Contract 1
    -- Contract 2
    -- Contract 3

    I have gone through what must be hundreds of variations and combinations of was of displaying these pages, but nothing keeps the submenu's there at all times.

    It should be noted then when in the other main headings such as About Us or Portfolio, these all have their own submenu's that work, but the contracts page is the only one with sub pages of the pages if you get my meaning.

    Here is the code:

    </div> <!-- end of #content -->
    <div id="sidebar">
    
    <ul>
     <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
    
    <?php
    if($post->post_parent)
    $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); else
    $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
    if ($children) { ?>
    <h2 style="width: 90%;">Sub-menu</h2>
    </ul>
    <ul>
    <?php echo $children; ?>
    </ul>
    <?php } ?> 
    
    	<!-- Freak -->
    	<li id="sidebar-splitted">
    
    		<div class="splitted-left">
    			<h2 style="width: 90%;">Rouse News</h2>
    			<ul class="splittedlists">
    				<?php wp_list_cats('sort_column=name&optioncount=0&hierarchical=1'); ?> 
    
    		</div>
    
    		<div class="splitted-right">
    			<h2><?php _e('Archives'); ?></h2>
    			<ul class="splittedlists">
    				<?php wp_get_archives('type=monthly&limit=12&show_post_count=0'); ?>
    
    		</div>
    
    		<div class="searchbar">
    			<?php include (TEMPLATEPATH . '/searchform.php'); ?>
    		</div>
    
     <?php endif; ?> 
    
    </div> <!-- end of #sidebar -->

    This is the important section of that code:

    <?php
    if($post->post_parent)
    $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); else
    $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
    if ($children) { ?>
    <h2 style="width: 90%;">Sub-menu</h2>
    
    <ul>
    <?php echo $children; ?>
    </ul>
    <?php } ?>

    with the wp_list_pages being the part that decides which pages to display. Also here is a reference to the wp_list_pages function that may help: http://codex.wordpress.org/wp_list_pages

    Genuine major thanks to anyone who can help me on this ???

  2. djmccabe
    Member
    Posted 5 years ago #

    48 hour bump...please help!

  3. adamrice
    Member
    Posted 5 years ago #

    You are asking this on the WordPress forums. Hate to break it to you.

    I'm trying to understand what you want here. It sounds like you've got a 3-layer hierarchy:
    About Us
    ...
    Contracts
    - Completed
    -- Contract 1
    -- Contract 2
    -- Contract 3
    -In Progress
    -- Contract 4
    -- Contract 5
    -- Contract 6
    Portfolio
    ...

    If you are at the top of the hierarchy, you don't want to show any sub-pages; if you drill down into the hierarchy, you want to show all sub-pages below Level 1, regardless of how deep you are. Correct me if I'm wrong.

    Assuming I'm right, there's no obvious function to accomplish it. You'd need a block of code that walks up the hierarchy to the top to get the oldest ancestor of the current page, and then display all the sub-pages of that ancestor. In very rough pseudo-code, it would look like this:

    if I'm not at the top of the hierarchy {
      $hit_top = false;
      $me = $post->ID;
      repeat until $hit_top == true {
        if parent of $me == true { $me = parent of me }
        else { $hit_top = true }
      }
      wp_list_pages(child_of='.$me);
    }

    I haven't examined WP's code to see if there's already a function that does this, or part of this--there might be, and if you can find it, it would make this a little simpler.

Topic Closed

This topic has been closed to new replies.

About this Topic