tags:

views:

29

answers:

1

Hi guys and gals, here's one for the brightest of you:

I've built a huge dynamic child page lister.

I have 3 levels, here's an example:

  • Parent
    • child
      • sub child
      • sub child
    • child
    • child
      • sub child
      • sub child

Here’s how it needs to work:

When on the parent, show this:

  • Parent (current)
    • child
    • child
    • child

When clicked into the child which has subs, needs show this:

  • Parent
    • child (current)
      • sub child
      • sub child
    • child
    • child

(the same would be shown, if the user proceeds into the sub child)

Here's when I run into trouble: I'm using wp_list_pages to generate the lists and depth to show subs when I need to, problem is, it gives me all subs in the stack, even though, I only need the subs of the current page (or of the current pages' ancestor, which would be a first-child in the tree) to be shown and the other subs hidden, while showing all children.

So instead of showing the list above, it gives me the full list:

  • Parent
    • child (current)
      • sub child
      • sub child
    • child
    • child
      • sub child
      • sub child

Now I can easily get the list of current siblings, can get the children of current, it's place in the tree, no problem, I can even solve this by separating the wp_list_pages output and bringing the current to the top, it's subs right under it and the other non-open pages below it, but this is not the objective.

So, is there anyone that can figure this one out?

On a side note: Here's a not-very-kosher jQuery workaround I made (removing the unnecessary elements with javascript), the issue still remains, can we make wordpress do this without javascript hacks?

$("#side_nav li").not(".current_page_item").not(".current_page_ancestor").not(".current_page_parent").has("ul.children").children("ul.children").remove();
+1  A: 

you can use get_children for it.

i usually put a function in functions.php for mindless retrieval in the right order like

function get_kids($id) {
  get_children('post_parent='.$id.'&order=ASC&orderby=menu_order&post_status=publish')
}
Neil Sarkar
That would make a separate list, I'm aware of this functionality.What I'm after is: only showing children of current within the same wp_list_pages hook.
Kirill