Welcome to Dagon Design. In addition to free scripts, WordPress plugins, and articles, we offer a variety of services including custom theme design, plugin creation, and PHP scripting. Contact me for more information.

Version 1.0   Updated Friday, February 20th, 2009 at 7:19pm

List Subpages Plugin for WordPress

This WordPress plugin generates a list of subpages for the page being viewed. You can use this plugin by inserting the trigger text in your page (where you want the list to appear), or by calling the function directly from your template file. One key feature of this plugin is that it can used outside the loop, which means you can display a list of subpages of the current page in your header, sidebar, or anywhere else. There are also several options available. You can change the sort method, exclude pages, adjust the page depth, show the date, and more.

Download

If you have found this page useful, please consider donating. Thanks!

Installation

  • Download the above file
  • Rename dd-list-subpages.txt from .txt to .php and upload it to your plugins directory
  • Activate the plugin from the WordPress admin panel
  • Configure the options under the admin panel: Options - DDListSubpages

Change Log

  • 04-06-07 Version 1.0 - First release.

Usage

To display the list of subpages on your page, just add the trigger text to your page:

<!-- ddlsp -->

(If you are using the visual editor in WordPress, you may have to temporarily disable it to add in the trigger text)

You can also call the function directly from a template file with the following command:

<?php echo ddlsp_generate(); ?>

If you use this method, it does not have to be in your loop, which means you can display the list of subpages anywhere you like in your theme.

Whichever method you use, just remember that it only generates the list when viewing an actual WordPress page which has subpages.

Options

Here are the options available for this plugin under the WordPress admin panel. The options page also includes a ‘load defaults’ button.

Before List

This text is added before the list of pages.

After List

This text is added after the list of pages.

Sort Column

You can choose to sort the list by page title, menu order, page date, page modified date, page ID, page author, or page name (slug).

Sort Order

This lets you choose between an ascending or descending sort.

Excluded Items

This is a comma-separated list of page IDs you want to exclude from the list.

Included Items

This is a comma-separated list of page IDs you want to include. If you use this feature, only pages manually specified will be listed.

Page Depth

This is the depth of subpages that will be shown. The default is 1, and 0 means no limit.

Show Date

If enabled, the date will be shown after each page.

Date Format

If showing the date, this is the PHP date format that will be used.

List Title

This is an optional header for the list of pages.

Pages: [7] 6 5 4 3 2 1 » Show All

  1. 105
    Paul Parenko

    This is how to get the whole children list, please add this as an example!

    post_parent){
    // will display the children of this top site
    $children = wp_list_pages(”title_li=&child_of=”.$post->ID.”&echo=0″);
    }else{
    // diplays only the children of
    //$children = wp_list_pages(”title_li=&child_of=”.$post->post_parent.”&echo=0″);

    if($post->ancestors)
    {
    // now you can get the the top ID of this site
    // wp is putting the ids DESC, thats why the top ID is the last one
    $ancestors = end($post->ancestors);
    $children = wp_list_pages(”title_li=&child_of=”.$ancestors.”&echo=0″);
    // you will always get the whole child list
    }
    }

    if ($children) { ?>

  2. Works nice and easy.
    Did exactly what I wanted!

  3. 103
    Darryl

    Hi,

    I am wondering, is there a way to make it so you can have more then one column. I would like to be able to change it from 1 column to 2 or even 3 columns. Any help would be great.

  4. Casey, I totally agree with what you say in #52.

    Anyone know how to do this?

    I use the php include method in a side bar. When you click on one of the sublinks, you are now on that page - which is a sublink, therefore the sublink list dissappears for the main page section.

    Anyone know of a way to click on a sublink and maintain the previous sublink list?

  5. 101
    Clair

    Another fix for those who wants to show the subpages of the parent rather than it disappearing when you go to the subpage itself

    In line 220, replace
    $thePostID = $wp_query->post->ID;

    with

    $thePostID = $wp_query->post->post_parent;
    if ($thePostID == 0) $thePostID = $wp_query->post->ID;

    I’ve only tested it if you have a page tree depth of 1 (that is, no subpages of subpages), because that’s all I needed it for

  6. 100
    leon

    would be good if it maintained the context.

    as in when you click on a subpage, the subpage’s class becomes current, and the subnav does not vanishes.
    at the moment it vanishes, braking browseable navigation

  7. Brilliant plugin. Looks great. Thank you.

  8. Same as what Tim said. I’ve placed the function call in side of a template. It displays great on the parent page, but once I go into one of the child pages, I lose the subpage listing.

    Same thing, need to show sibling pages.

    Thanks!

  9. 97
    Tim

    This is a great plugin and works perfectly, but is there any way of adjusting it to also show sibling pages? When I navigate to a subpage I need the subpage menu of the parent page to start there… any ideas?

  10. 96
    Raquel

    This works perfectly, exactly what I needed, thanks!

  11. A great plugin, works like a charm with 2.7.1!

  12. Is there a way to show comments for the pages listed?

    Like so:

    * abortion. 03/08/09 (7 comments)
    * domestic violence. 02/28/09 (5 comments)
    * online infidelity. 03/17/09 (1 comments)

  13. This plugin has been tested in the latest release of WordPress (2.7.1)

  14. Very effective and just what I needed. Thank you!

  15. Great plugin, thank you.

Pages: [7] 6 5 4 3 2 1 » Show All

Leave a Comment

Before you comment: If you are having an issue with a script, please make sure you have read the entire article. Also, please read through the comments because most common issues have already been discussed many times. Thanks.


Be sure to wrap all code in <code></code> tags.