WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Listing Page (wp_list_pages) problem (2 posts)

  1. kwestalot
    Member
    Posted 1 year ago #

    I'm having some difficulties with listing pages dynamically using WordPress syntax.

    I have an attorney site that I'm working on, and I'm simply trying to list the parent categories, as well as the child pages - and the child's child pages.

    Here's the URL of the site for a visual:
    http://kirkcdavis.com/wordpress/dui/dui-penalties/

    And here is the structure of the navigation that I ideally want:

    -DUI
    --Court
    --DUI Arrest
    --DUI Penalties
    ---Ignition Interlock Device
    ---Electronic Home Monitoring
    ---Victim Impact Panel
    ---Alcohol Assessment
    ---Alcohol Information School
    ---Alcohol Treatment
    ---Mandatory Penalty Chart
    ---Probation
    --License Suspension

    I want it to show all 4 headings (parents): Court, DUI Penalties, DUI Arrest and License Suspension - and then list the child pages for that particular page, while keeping the other parent categories.

    I have this partially working, with the top side navigation of the page (http://kirkcdavis.com/wordpress/dui/dui-penalties/) listing the 4 parent categories, but none of the child ones. And the code for this I'm using is the following:

    <div id="sidebar">
        <ul id="subnav">
    
    		<?php wp_list_pages( array('title_li'=>'','include'=>get_post_top_ancestor_id()) ); ?>
                  <ul>
                      <?php wp_list_pages( array('title_li'=>'','depth'=>1,'child_of'=>get_post_top_ancestor_id()) ); ?>
    
                  </ul>
       		</li>
        </ul> 
    
    </div>

    Then, the bottom sidebar examples on the page (http://kirkcdavis.com/wordpress/dui/dui-penalties/) lists the main overall category (DUI) and then jumps to the sublistings of DUI Penalties, but doesn't list DUI Penalties or any of the other 3 parent categories.

    Here's the code I'm using for this section:

    <div id="sidebar">
        <ul id="subnav">
          <?php wp_list_pages( array('title_li'=>'','include'=>get_post_top_ancestor_id()) ); ?>  
    
          <?php global $post; $thispage = $post->ID; // grabs the current post id from global and then assigns it to thispage ?>
            <?php $pagekids = get_pages("child_of=".$thispage.""); // gets a list of page that are sub pages of the current page and assigns then to pagekids ?>
            <?php if ($pagekids) { // if there are any values stored in pagekids and therefore the current page has subpages ?>
            	<ul>
            		<?php wp_list_pages("depth=1&title_li=&sort_column=menu_order&child_of=".$thispage); // display the sub pages of the current page only ?>
                </ul>
            <?php } else { // if there are no sub pages for the current page ?>
            	<ul>
            		<?php echo wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0'); ?>
                </ul>
    
            <?php } ?>
    
            </ul></div>

    So I think I'm close, but for some reason can't figure this out. I need a combination of the two - where again, I will have all 4 parent pages/categories and then the subpages for that particular parent page. Hope this makes sense. If I can clarify anything, let me knwo. And thanks for looking and your help!

  2. kwestalot
    Member
    Posted 1 year ago #

    Figured it out.

    Followed this structure:
    http://www.focus97.com/blog/web-design-and-development/wordpress-nav-solved-how-to-list-child-pages-only-for-current-parent-page/

    And ended up with:

    <div id="sidebar">
    <ul id="subnav-main">
    <?php wp_list_pages( array('title_li'=>'','include'=>get_post_top_ancestor_id()) ); ?>
    </ul>
    <ul id="subnav">
    
    <?php if(!$post->post_parent){
        $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
        }else{
        if($post->ancestors)
        {
        $ancestors = end($post->ancestors);
        $children = wp_list_pages("title_li=&child_of=".$ancestors."&echo=0");
        }
        }
        if ($children) {
        ?>
        <ul> <?php echo $children; ?></ul>
        <?php } ?>
        </ul>
    </div>

Topic Closed

This topic has been closed to new replies.

About this Topic