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: « 9 8 7 6 5 [4] 3 2 1 » Show All

  1. 60
    JakoThan

    Hi!
    Very nice plugin! Well done!
    But there is little problem… I really need a third level for my sub pages. So, it works, but the second level does not shown when the third level is active.
    Can you help me? PLEASE! :)

    Thanks so long!

    Thomas

  2. Hi, I would like to know how i could modify the ligne 273 :
    $content = preg_replace(‘/\s*\s*/i’, ““, $content);
    because I don’t want my links to be in a list, and this is the only ligne that I think could help me do that, but I don’t understand nothing to that strange html code.

  3. June: In WordPress 2.5 it is now called ‘Settings’. Look to the right of the page.

  4. Hi! I am currently using WP 2.5 and has become a nightmare xD
    Anyway I can’t find this anywhere in WP 2.5???

    “Configure the options under the admin panel: Options – DDListSubpages”

    Where is it located? thanks!!!

  5. 56
    scott

    great plugin!!!

    the change suggested in comment #41 worked great for me.

    i was having a problem getting pages without subpages to validate because of the empty tags.

    i just replaced the line
    $t_out = $before_list . $t_out . $after_list;
    with

    
    if ( $t_out != '' ){
      $t_out = $before_list . $t_out . $after_list;
    }
    

    this way, if there are not any sub pages, it doesn’t display anything.

  6. Okay, I’m apparently a moron. I can’t seem to get any of the configuration options to work. Where does one accomplish this? I’ve been modifying the code directly. Am I stupid? Probably, but please help anyway.

    
    // Set defaults if options do not exist
    add_option('ddlsp_before_list', '<ul>');
    add_option('ddlsp_after_list', '</ul>');
    add_option('ddlsp_sort_column', 'post_title');
    add_option('ddlsp_sort_order', 'asc');
    add_option('ddlsp_exclude', '');
    add_option('ddlsp_include', '');
    add_option('ddlsp_depth', 1);
    add_option('ddlsp_show_date', FALSE);
    add_option('ddlsp_date_format', 'l, F j, Y');
    add_option('ddlsp_title_li', '');
    

    This should keep the date from displaying, correct?

  7. Hey Dagon – you rock…every time I set up a site I spend ages rummaging around for plugins without much luck and after hours and hours normally end up at your site to see that you have already solved the problem. When am I going to learn to just come right here to begin with? Cheers a lot – you always seem to come up with the glue that holds unconventional uses of Wordpress together. You the man!

  8. Hi,
    I’d like to move the List Title before the ‘ul’ tag, in order to do not include it into the list. How can I modify the plugin file?

  9. 52
    Casey

    @Luke (#41, #44)
    I still get a disappearing sublist when I click on a subpage link… do you have a working version of this where the subpage list stays visible as long as you are in the “section” of the parent?

    (eg. fruit (parent) displays apples, oranges, pears… if you click pears, make the list stay visible. when in the veggies, show celery, carrots, peas and keep that list visible when on any of those veggie pages)…

    I think this is what most folks want – a dynamic list of child pages that stays visible until you change the parent (think section). In my case, I have the parents in a horizontal menu at the top… I want the sub page list to display in my sidebar, staying visible at all times until I click a different main page.

  10. 51
    Casey

    Hi, Aleister…
    is there some way to use the list subpages plugin so that when you click on one of the listed subpages, it still displays the list from the parent? currently, the list disappears (since the clicked link goes to a child that doesn’t have subs of its own).

    I’ve tried the code substitution suggested in #41 & #44 (Luke) but it doesn’t do what I describe above…

    I’d pay to have this working, as I have struggled with lots of methods (I’m showing this in my sidebar file) and wasted lots of time already.

    Please contact me for further info or a link to the site I am trying to develop.

    Thanks!

  11. Hi,is there any where that I can assign CSS to this plugin?

  12. 49
    misty

    Updates:

    1. Well, I had to remove the plugin(dd-list-subpages.php) because it causes the following warnings at Admin login, saving files and etc. The warnings prevent me from login.

    Warning: Cannot modify header information – headers already sent by (output started at …/wp-content/plugins/dd-list-subpages.php:300) …

    Not sure how to fix this one.

    2. Given that fact that a thread may be extended for weeks or months, the post updated date info would be nice instead of creation date of a post or a page.

    Thanks.

  13. 48
    misty

    Okay, it’s working now. I have one question:

    I am using Post Updated plugin(Display notice/date/time of when a post was last updated. By Kaf Oseo.) Is there such a way that I can tweak it to show the last updated dates?

    Thanks.

  14. 47
    misty

    Uh, the \par’s are from WordPad editor. The file is clean now and I have activated the plugin.

    But not clear about how to add trigger text. Could you give an example please? thanks.

  15. 46
    misty

    Hi,

    I have copied dd-list-subpages into the Plugin directory and getting this error when trying to activate it:

    “Plugin could not be activated because it triggered a fatal error.”

    I’ve noticed that \par’s being added everywhere to the file After copied to the Plugin directory.

    By the way, regarding the 11-27-07 entry, there is a typO “ddspl_generate function” which is meant for “ddlsp_generate()”

Pages: « 9 8 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.