开发者

Getting wordpress wp_list_pages to list only relevant children (hard as hell)

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 t开发者_JS百科ree, 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();


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')
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜