Support » Fixing WordPress » Listing Page (wp_list_pages) problem

  • Resolved kwestalot


    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:

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

    –DUI Arrest
    –DUI Penalties
    —Ignition Interlock Device
    —Electronic Home Monitoring
    —Victim Impact Panel
    —Alcohol Assessment
    —Alcohol Information School
    —Alcohol Treatment
    —Mandatory Penalty Chart
    –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 ( 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()) ); ?>
                      <?php wp_list_pages( array('title_li'=>'','depth'=>1,'child_of'=>get_post_top_ancestor_id()) ); ?>

    Then, the bottom sidebar examples on the page ( 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 ?>
            		<?php wp_list_pages("depth=1&title_li=&sort_column=menu_order&child_of=".$thispage); // display the sub pages of the current page only ?>
            <?php } else { // if there are no sub pages for the current page ?>
            		<?php echo wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0'); ?>
            <?php } ?>

    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!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Listing Page (wp_list_pages) problem’ is closed to new replies.