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.

Updated Friday, April 6th, 2007 at 4:16pm

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

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.

  1. thank you very much for your helpful plugins.

  2. thanks.

  3. How can I code the submenu to not overlap the top menu? http://www.abovethecrowdphoto.com/index.php (look on the services page)

  4. Thank you so much! I’m a noobie and the struggle with the php code was really eating into my writing time. Thank you for this plugin, it was exactly what I needed and really easy to use. bama :)

  5. The sublist doesn’t seem to work with private pages, even though the logged in user has the capabilities to read private pages.

  6. 61
    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

  7. Genius! Thank you!

  8. 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.

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

  10. 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!!!

  11. 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.

  12. 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?

  13. 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!

  14. 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?

  15. 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.

  16. 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!

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

  18. 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.

  19. 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.

  20. 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.

  21. 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()”

  22. 45
    misty

    I have a page which has a couple of linked other pages on it. Currently, I have manually put in the dates for the linked pages. I am searching for a plugin that can show the dates and author just like what the following forum page does.

    http://www.weberforums.com/forum4.html&sid=f7db7635c083e86b48b7c5ede846ad3b

    Would this plugin work for my case?

    Thanks.

  23. Sorry ammendment, only replace $thePostID = $wp_query->post->ID;

    You still need the $wp_query bit.

  24. Good point :)

    You need to replace this code inside the ddspl_generate function:

    
    global $wp_query;
    $thePostID = $wp_query->post->ID;
    

  25. Hey Luke, where do we add the code you posted? Thanks a bunch!

  26. Just found a solution to a problem that some people have mentioned.

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

    What this does is says if there is a post parent (page parent in this case, silly wordpress terminology), use the id of this parent to list the subpages from. Otherwise, if there is no parent page, use the current page id. Hope that helps.

    Very nice plugin by the way :)

  27. To asshat #39….the reason is obvious. Why the hell would you want to see the sub-navigation of a section you’re not even looking at? These aren’t drop-down menus.

    To the author….thanks for a sweet plug-in!

  28. 39
    alias

    I got to say, I like this plugin but the way its designed to only list subpages on pages with subpages is the most stupid thing i ever heard

    who would make a plugin to list only subpages on a page with subpages and not the rest of of the subpage list ? this plugin is really unusable as is, but i hope the creater will fix it and make it work the way it should.

    back to searching for a functional plugin

  29. 38
    alias

    how come when you click on a subpage listed the rest of the list disappears ? This would render the plugin rather useless no ?

  30. 37
    alias

    damn i know why its not working because i don’t have any sub pages doh!!

  31. 36
    alias

    the plugin itself isn’t working i get a blank list, using wp 2.3

  32. 35
    alias

    sorting isn’t working,

  33. How do I stop the plugin from saying “This page has the following subpages…” at the bottom of my subpages? I didn’t put the call in there and can’t find it in the plugin…

  34. Hello, very good plugin but I have a question : I hava a plugin ( Page Category Plus) with which I can assign pages to categories.

    Rather than listing subpages of a page, I would like to list pages & subpages inside a category.

    How can I modify the query to make this ?

    Thanks a lot !

  35. Hi! Works fine for me but with one problem:
    When i’m on a subpage and there are no more subpages the navigation is lost.

    Maybe there is a possibility to show the subpages of a page also on the subpage?

    Regards
    Mario

  36. Great plugin! Is there a way to place your plugin on a widget?

  37. 30
    Eddie

    And yes I have subpages on the page I’m trying to get this on just to note.

  38. 29
    Eddie

    I put in the trigger text into a page and nothing at all happens. Your plugin seems very easy to set up, just upload and use trigger text so I don’t see how I missed anything???

  39. Right now I have it set by default to depth of 2, how can I show depth of 1 on a different page without messing up the one that shows depth 2. Can I add that info inside the brackets?

  40. 27
    Mike

    Hello

    How can i add “nofollow” to the links?

    Thanks Mike

  41. 26
    Trevor

    How can I get the new links to not show up in the main top navigation? I want to be able to just add sub page links to different pages but not show up in the main nav

  42. 25
    Damian Taggart

    Is there a way to prevent the “before list” and “after list” HTML from being displayed on pages that don’t have a subpages?

    Thanks!

  43. I’m not seeing the list of subpages on the same level as the current subpage when on a subpage. It works find on pages. Is there a setting that you have to change to see it? (I’m using the php call, if that helps).

  44. Scott: That plugin works a bit differently I believe, although I have not used it.

  45. So, does this plugin work like* the one mentioned above (http://www.webspaceworks.com/resources/wordpress/30/)?

    Does if dynamically list subpages changing he list (in the sidebar) per the current page being shown?

    Thanks.

  46. Manly: It might help to be a little more specific.

  47. plug in doesnt work for me.

  48. nice! would be nice if this supported multi-column output like some of your other plugins.

    However, doesnt appear to be a minor change as I think one would have to use get_pages() instead and traverse manually.

  49. Donna: That would be possible, but it would require a decent amount of modifications. Unfortunately due to the number of requests I receive, I am not able to create custom versions for everyone.

  50. Would it be possible to make this work like your form plugins where you can have more than one sublist options page? So, and and so forth…

    This would be extremely useful to customize how this works for a “press releases” page (show by date) versus some other kind of page where you would want to order by menu order or something.

    As always, great work!

  51. Gigi: You must give it the ID of a page with sub-pages, and the sub-pages will be listed on that page. If you just give it the ID of a sub-page, it will not work properly.

  52. Wow. Such a great and easy plugin. Even works with K2.

  53. 14
    Gigi

    This plugin is wonderful and seems to work perfectly. (wordpress 2.2 for me)

    Only when i try to INCLUDE a specific subpage with its ID it does not work.
    Do you know why ?

  54. Ruzel: This plugin only lists child-pages of the current page.

  55. This is a great plugin. I’m not really sure how it’s different from wp_list_pages(), but regardless, the code is solid. If anyone came here, like me, though, looking for a way to list sibling pages, check this code:

    http://www.webspaceworks.com/resources/wordpress/30/

  56. Stephan: Thanks for the heads up - fixed ;)

  57. I just came across your neat plugin. However, I have a suggestion that has nothing to do with it. :)
    Recently I changed my browser’s default background color and font to something else than the default white and Times New Roman to see who has set it on their website and who forgot it. And you… yeah, go figure. ;) It’s interesting how many websites (and even some of the big ones) forget it and the sites look really crappy then.

    You might wanna set a body background color in your stylesheet. ;)
    Cheers!

  58. 9
    Byron

    ok thanks :)

  59. Byron: This plugin only works on pages that have sub-pages.

  60. 7
    Byron

    Hi,

    I’m come to the same roadblock as Ash.

    I have an About page that displays 6 of its child page links in the sidebar. Once I go to one of the child pages, the list in the sidebar is gone ie. it doesn’t display its sibling pages any more.

    I can see why as I’m is no longer on a page with subpages. Would there be a workaround?

    Here’s hoping and many thanks for the plugin :)

    Byron

  61. Ash: It should do that actually. Even if you are on a sub-page already.

  62. Hi,
    I am looking for a plug in that will display subpages in a heirachy. EG. “Page one” has seven subpages. Each “subpage” has “100 sub-sub pages” and each sub-sub page has “10 sub- sub-sub pages” Does this plug in order these and how does it display if so?

    CVheers
    Andy

  63. This is a really handy plugin!

    I have a question though, would it be possible to view the list of subpages if you are viewing a subpage from that list?

  64. Jordan: I will keep that in mind for all my plugins actually :)

  65. The only suggestion I have for the plugin is on the admin page, you have “load default options,” and then “update options.” Most forms will have a submit/reset (in that order) so I noticed that I will keep going to “load default options” rather than update options. Not sure if anyone else would prefer it that way, but just figured I’d mention it.

    Otherwise nice plugin =)

  66. Thank you!!!!

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.