WebspaceWorks Resources

Fold page list

WordPress 1.5 introduced the ability to maintain pages through the WP database, and to output a list of pages as a navigational list using the wp_list_pages template tag. While useful, certain aspects of use of this tag fall short of being able to selectively expand/fold/collapse sub layers of a page hierarchy, with the result that page lists can become long, unwieldy and often difficult or confusing to use.

Fold Page List has been developed to provide some control on how Wordpress displays the hierarchy of its page menu.


Fold Page List is based upon wp_list_pages, get_pages and _page_level_out, modified and renamed for this plugin.

In action


This enables the existing functionality of wp_list_pages to be retained (in fact the available arguments are the same as for that tag), while extending it to support the selective folding of sub-page lists on all pages other than the selected page.


Simply place the expanded file fold_page_list.php in the path ‘/wp-content/plugins/’ in your WordPress installation, and activate it in the admin interface.

All function names include the initials ‘wswwpx’ in a prefix, so there should be no conflicts with any other functions.

WP2 compatibility: fold_page_list remains compatible with the release version of WP v.2.1.


Fold Page List would typically be used to replace the functionality provided by the wp_list_pages tag that is usually found in the sidebar.php file in your active theme, itself located in wp-content/themes folder of your installation. To use, simply replace the code fragment that looks like this
<?php wp_list_pages ($arglist); ?>
with this:
<?php wswwpx_fold_page_list ($arglist); ?>
You can even use the same arguments as in the original call.

$arglist is optional and conforms exactly to those supported by the wp_list_pages tag that comes with WordPress 1.5, and which is explained in the Wordpress Codex.

Version 1.1 adds a new optional argument to the call sequence to control how groups of pages unfold. The revised call is:
<?php wswwpx_fold_page_list ($arglist, $fullunfold); ?>

$fullunfold is optional and can be either TRUE or FALSE (default). The purpose of this argument, which is not supported by the original wp_list_pages tag, is to determine whether a section is fully unfolded from its root parent to its lowest descendent, or limited to the immediate children of the current page.

Since Fold Page List is built on top of wp_list_pages, it should retain all functionality of that tag, but enhance it with these further capabilities.

Revised functionality (version 1.8 onwards): Breadcrumbs

  • Introduce a new tag for use in templates (wswwpx_page_breadcrumbs) to generate breadcrumb lists of ancestors to the current page.
  • Call as: wswwpx_page_breadcrumbs($homelink, $separator, $echo); where (default values in brackets):
    • $homelink: array(’label’=>’Home’, ‘title’=>’Homepage’, ‘link’=>’/')
    • $separator: string(’&nbsp;&raquo;&nbsp;’)
    • $echo: boolean (true)

Revised functionality (version 1.6 onwards): Drop-down capability

  • Introduce a non-folding capability through extended values to the $fullunfold argument. Values may be:
    • FALSE (default): Standard, stepwise unfolding as you navigate through the page list
    • TRUE: Will fully unfold the current section down to any level specified in the $arglist
    • 2 (the number 2): No unfolding will happen. This makes the plugin act exactly as wp_list_pages, but with the page hierarchy fully styled
  • This latest change now allows the full page hierarchy to be output in the html, but with styling that allows sections to be selectively hidden, and so to act as the basis for a drop-down page navigation.

Revised functionality (version 1.4 onwards)

  • Retain “page_item”, “current_page_item” and “current_page_ancestor” classes on page links as appropriate, but extend functionality further:
    • Add “page_folder” to all links that have children, even if that sub-hierarchy is not expanded
    • Pages with children, but which are not expanded will have the classes “page_item” and “page_folder” applied to them
    • Pages where their hierarchies are expanded to show children will have the classes “current_page_item” or “current_page_ancestor” and “page_folder” applied to them
    • Pages at the end of a sub-hierarchy (i.e. that have no children) will have either the “page_item” or “current_page_item” applied
  • Separate styling of pages with/without children (for example, applying custom bullets) can now be easily achieved through suitable modification of the stylesheet.

Revised functionality (version 1.1 onwards)

  • Expand either
    • the sub-hierarchy of the currently requested page to one layer down by omitting the second argument or setting it FALSE, or
    • the complete section from topmost parent to the depth specified by the depth argument of wp_list_pages by setting the second argument TRUE
  • Retain “page_item” class on all page links, but differentiate the navigation trail by adding:
    • current_page_item” to the link for the currently requested page
    • current_page_ancestor” to the links for all ancestors of the currently requested page
  • Keep all other sub-hierarchies collapsed to their parent
  • Allow the use of custom title attributes in the anchor tag. (Introduced in 1.0b6 [rc3])
    You will need to add the custom field “wswpg_linkttl” to each page where you wish to use this feature. Without this Wordpress standard practice of using the same text for visible text and anchore title will continue.


Current version (v1.9): fold_page_list.php.zip [28 December, 2008].


  • 28 December, 2008: Current version (v1.9): Compatibility with All-in-One-SEO Pack and Page Menu Editor plugins

    • Modifications to extraction of metatags to prevent All-in-one-SEO titles appearing in navigation menus and to provide support for Page Menu Editor functionality
  • 29 June, 2008: New Feature
    • Added new tag for use in templates wswwpx_page_breadcrumbs to generate a breadcrumbs list of ancestors to the current page.
  • 02 May, 2008: (v1.76): Bugfix
    • Fix bug (introduced in v1.75) that affected section-wise unfolding of page hierarchy
    • Fix Fix bug that affected Fold Page List when used with SEO plugins (e.g wpSEO) causing some navigation links to be desplayed blank
    • Amended contact email address in header
  • 28 February, 2008: (v1.75): Bugfix
    • Fix a minor bug in internal function (_wswwpx_get_ancestor_ids) returning root-relative page hierarchy
  • 22 February, 2007: (v1.74): Bugfix
    • Full fix for array handling issues that were sometimes generating warning messages
  • 21 February, 2007: (v1.73): Patch
    • Temporary fix to suppress warnings relating to array manipulation while a more robust correction is explored
  • 19 February, 2007: (v1.72 - not released): Behaviour correction
    • Makes section-wide fullunfold behave more consistently, such that any navigation within an unfolded section no longer causes parts of it to collapse.
  • 18 February, 2007: (v1.71): Compatibility fix for WP2.1
    • Fixes to internal function so that fullunfold by section now works with WP2.1
  • 17 February, 2007: (v1.7 not publicly released): Bugfix
    • Fixes problem of fullunfold on deep hierarchies of pages. Tested to a depth of 7, but essentially supporting infinite depth
  • 28 December, 2006: (v1.6): Feature enhancement
    • Extends the use of the ‘fullunfold’ argument to take a numeric value of 2, to bypass all folding and duplicate the wp_list_pages behaviour, but with full styling of the whole hierarchy.
  • 25 November, 2006: (v1.5): Bugfix
    • Fixed a problem where non-static children (e.g. attachments) were being included in the descendants list, causing the ‘page_folder’ class to be applied where it wasn’t needed.
  • 11 August, 2006: (v1.4): New feature
    • Added page_folder class to any link that has children, irrespective of whether or not those children are currently being displayed in an expanded hierarchy
  • 25 April, 2006: (v1.3): Compatibility fix
    • Compatibility with Subscribe2 plugin [www.skippy.net] (hack around a conflict between polyglot & subscribe2 plugins’ apparently conflicting use of the_title filter on subscribe2 confirmation pages only).
  • 14 February, 2006: (v1.2): Feature enhancement & bugfix (previously unreleased)
    • Brought up to date with current wp_list_pages capability in support of filters applied to the page list (suggested by Timm Severin)
  • 11 December, 2005: (v1.1): Feature enhancement & bugfix
    • Added new css class (“current_page_ancestor”) to allow for separate identification of current item from its ancestor trail.
    • Adds new argument (true/false) to enable full unfolding (to a limit of “depth”) of a section. Default FALSE.
    • Bugfix to internal function _wswwpx_page_get_child_ids to correctly return array of child ids.
  • 10 November, 2005: (v1.0.1): Polyglot support
  • 28 September, 2005: (v1.0 [final]): Release
    • No new features or bug fixes, just a change to the header to reflect its release status
  • 14 August, 2005: (v1.0b6 [rc3]): New feature.
    • Added the ability to use custom title attributes in anchors. Needs “wswpg_linkttl” custom field added on pages where this is wanted
  • 23 May, 2005: (v1.0b5 [rc2]): Bugfix.
    • Fixed problem of sub-pages being duplicated in a list when non-zero “child_of” argument given
  • 4 May, 2005: (v1.0b4 [rc1]): Bugfix.
    • Fixed broken xhtml validation (bad placement of </li> tag in _wswwpx_tree_sublevels_out)
  • 26 April, 2005: (v1.0b3): Bugfix.
    • Fixed for when no $queried_obj->ID available, causing problems when ancestor array tested against.
  • 24 April, 2005: (v1.0b2): Bugfix.
    • Reference to __('pages') in wswwpx_fold_page_list fixed
  • 22 April, 2005: (v1.0b1): 1st public release

Technorati Tags: , , , ,

Webspace Works: Effective website design, development & search engine optimisation

Simply effective, web design that works!

W3Csites.com Web Standards Group: Promoting Accessibility and standards across the internet This page uses valid CSS
This page uses valid XHTML 1.0 Transitional This page works in all modern browsers Sitening perfect score Real Design Network Approved