• Many of the pages on my site will have child pages attached to them (e.g. “About Us” will have a “Contact Us” child page). Right now, I can have wp_list_pages() just list the parent pages (ie. level=1 option)– and if I use level=0, it will display all of the child pages (which I don’t want as many of my pages will have child pages).

    Is there a way to figure out if the page that is selected/active has “child pages”, and, if so, list out the child pages using wp_list_pages() or any other function?

Viewing 8 replies - 31 through 38 (of 38 total)
  • I think I had a similar problem.

    I had a page item with 3 submenu items.
    My submenu was above the page content, not in the sidebar.

    Clicking the (parent)page item displayed the 3 submenu links. On the submenu pages itself the submenu did not display.
    So going to another submenu page required to click the back button to get to the parent page first.

    Thats the code for the submenu that solved it for me:

    $thispage = $wp_query->post;
    if($thispage->post_parent!=0)
    {
    wp_list_pages(“title_li=&child_of=”.$thispage->post_parent);
    }
    else
    {
    wp_list_pages(“title_li=&child_of=”.$thispage->ID);
    }

    hope that helps anyone

    regards,
    marcus

    wow, i just spent hours trying to do what marcus’s code pulls off. This works like a charm! thanks so much

    mine looks like this

    <!– parent navigation –>
    <div id=”navcontainer”>
    <ul id=”navlist”>
    <!– lists the pages from mysql database –>
    <li id=”active”><?php wp_list_pages(‘sort_column=menu_order&depth=1&title_li=’); ?>

    <!– the subnavigation, children –>
    <div id=”navcontainer”>
    <ul id=”navlist”>
    <li id=”active”> <?php
    $thispage = $wp_query->post;
    if($thispage->post_parent!=0)
    {
    wp_list_pages(“title_li=&child_of=”.$thispage->post_parent);
    }
    else
    {
    wp_list_pages(“title_li=&child_of=”.$thispage->ID);
    }?>

    </div>

    Part of that got cut-off…here it is again

    <!– Top level navigation, Parent –>
    <div id=”navcontainer”>
    <ul id=”navlist”>
    <!– lists the pages from mysql database –>
    <li id=”active”><?php wp_list_pages(‘sort_column=menu_order&depth=1&title_li=’); ?>

    <!– The subnavigation, children –>
    <div id=”navcontainer”>
    <ul id=”navlist”>
    <li id=”active”> <?php
    $thispage = $wp_query->post;
    if($thispage->post_parent!=0)
    {
    wp_list_pages(“title_li=&child_of=”.$thispage->post_parent);
    }
    else
    {
    wp_list_pages(“title_li=&child_of=”.$thispage->ID);
    }
    ?>

    </div>

    Now does anyone know how to keep parent highlighted while navigating through children?

    example:
    About
    – Disclaimer
    – Contact
    – Story

    Having the current sublevel highlighted while keeping “About” highlighted. I imagine it’s more than in the CSS and might involve is_page() ?

    Any ideas appreciated.
    Thanks!
    Joe

    Try this plugin that was mentioned earlier.

    http://www.webspaceworks.com/resources/cat/wp-plugins/30/

    Then use the ancestor class in CSS to highlight your About page.

    Not sure if this belongs here, but I spent an entire week trying to find what I needed (and I thought is was SO simple).

    On my site I have one sidebar on all pages but to keep things clear, I only want the top level pages to show there. That was easily done with:

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

    Now on every page, I wanted to show only it's direct children. That's done by giving the above code the child_of parameter. Unfortunately it seemed impossible to get the page's ID. the_ID() ECHOES the post/page ID. Well, to cut a long story short, what eventually worked for me was this:

    <ul>
    <?php $current_page_id = $wp_query->post->ID;
    wp_list_pages("title_li=&child_of=$current_page_id&depth=1"); ?>
    </ul>

    I put all of the IN the loop.

    I just started using wordpress and do really like it. However I’m searching for ways to do some of what this topic is about. I’ve been playing with all of the example codes listed here but, I’m not really a programmer so some of it doesn’t really make sense to me, I’ve gotten it to do this:

    Cat1
    Cat2
    Cat3

    But when you click on a link it displays this in the sidebar:
    Cat1
    Cat2
    Cat3
    subcat1
    subcat2
    subcat3

    What I’m wondering is if there’s a way or does anyone have a piece of code they can share so that on the main pages you would see the categories as:
    Cat1
    Cat2
    Cat3
    But when you click on a category to view that page, you see it’s subpages:
    Cat1
    -sub1
    -sub2
    -sub3
    Cat2
    Cat3

    Also, if you clicked on sub1 you would still see the above layout of Category you’re in, all the sub pages listed under it, then the rest of the Categories listed under that.

    Appreciate any advise anyone has. I’ve tried the page_fold_list plugin and it seems to work, but it adds everything in as an unordered list and I can’t figure out how to just get them to look like links rather than the

      .

    Hi,

    There seems to be a little confusion here between ‘categories’ and ‘pages’. They are distinctly different things in WP terminology.

    The fold page list plugin does exactly what wishfull above describes, but for pages.

    If what you want is to be doing this for ‘categories’ then it is the fold category list plugin that you need.

    A download link and explanation of use is available from the Fold Category List support page

    Best regards

    Rob

Viewing 8 replies - 31 through 38 (of 38 total)
  • The topic ‘How to list the current page’s children?’ is closed to new replies.