Support » Fixing WordPress » wp_list_pages() sub-hierarchy?

  • Scenario: I have a series of pages & child pages for different purposes, let’s call them Blue-0, BlueSub1, BlueSub2, Red-0, RedSub1, RedSub2. I’m calling custom sidebar templates for each family of pages (e.g. sidebar-blue.php) – so I always know the ID of the Page at the top of my family’s sub-hierarchy.

    I’m trying to figure out a way to get wp_list_pages() to display a hierarchical listing of a specific subset of pages – such as showing the hierarchy of ‘Blue_xx’ pages anytime I’m on a page that has called sidebar-blue.php.

    Using ‘child_of=ID_for_Blue-0’ won’t do the trick, because it won’t display Blue-0 at the top of the hierarchy. Right now, I’m calling wp_list_pages() twice: once to list only Blue-0, then again to list children of Blue-0. This is serviceable, but kludgy – and requires manual formatting to indicate hierarchy.

    I see two possible solutions, but can’t figure out how to make either work.

    If anyone knows a way to make a call that would produce wp_list_pages(MyPageID_plus_ChildPages), that would be ideal.

    The other possible approach I can’t figure out is using custom keys/values. If I create a custom key for each page called ‘ck_color’, and assign a value of ‘blue’ to all my Blue pages, how do I format the wp_list_pages() call to filter on that? The Codex documentation suggests this can be done, but I can’t figure out how…


  • The topic ‘wp_list_pages() sub-hierarchy?’ is closed to new replies.