WordPress.org

Forums

How to list the current page's children? (39 posts)

  1. kendallinternet
    Member
    Posted 9 years ago #

    I too needed a variant of wp_list_pages() that expanded the current page's brother/sister pages, but collapsed parent, grandparent (etc.) and other pages in the sidebar.

    Adsworth's plugin was almost (but not quite) what I was looking for and (despite my best efforts) I was unable to modify it to create what I was after.

    However, I did yet more searching and I've now found the solution:

    It's a plugin called 'Fold Page List' and is written by WebSpace Works - download it here:

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

    Regards,
    Greg

  2. lynk
    Member
    Posted 9 years ago #

    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

  3. joegeb
    Member
    Posted 9 years ago #

    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>

  4. joegeb
    Member
    Posted 9 years ago #

    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>

  5. joegeb
    Member
    Posted 9 years ago #

    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

  6. Lari
    Member
    Posted 9 years ago #

    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.

  7. blender
    Member
    Posted 9 years ago #

    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.

  8. wishfull
    Member
    Posted 8 years ago #

    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

      .
  9. roblgs
    Member
    Posted 8 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic