What is it?
On my site, I use the WordPress Page hierarchy as a way of categorising all of my static posts. All the pages about my WordPress plugins, for example, are children of the /projects/plugins/wordpress page; all my articles are children of the /articles page.
What this system lacked, I thought, was the ability to list a parent Page’s subpages in a similar way to how category archives work - on my site, for example, the /projects/plugins/wordpress page will probably never have any proper content; it simply serves as a category, the parent of all the pages detailing my WordPress plugins.
So, I wrote this plugin to allow that. It adds two easy ways of displaying child Pages on a parent Page.
Download
Download List Subpages (Version 2.1)
List Subpages has been downloaded 5,892 times.
Installation
Simply upload the PHP file to your plugins directory and activate it.
Usage
Once you’ve got the plugin installed, you’ll want to be using it.
List Subpages works in two ways; you can either add a template to your Pages that displays the list right there, or you can create a Page Template1
Post Tag
This is probably the easiest method of displaying the hierarchy, but is slightly less flexible. For most people, however, it is perfectly adequate.
To use this method:
- Edit the page you’d like to display the hierarchy on.
At the point at which you’d like to display the hierarchy, insert the following tag:
<subpages />- You’re done!
Page Template
This method is a little more involved, but will allow you more flexibility and control over the display of the page hierarchy.
To use this method:
- Copy your theme’s
page.phpto a new file in your theme directory, calledlist-subpages.php. - Edit it and find the place where you’d like to display the hierarchy.
Paste the following code:
list_subpages();- The function will generate the ouput - just as it does with the template tag - within an HTML
divwith aclassoflist_subpages, allowing you to control how the output appears using CSS. - Edit the pages on which you’d like to display the hierarchy, and from the “Page Template” section on the right, choose the “List Subpages” template you just created.
- You’re done!
For Kubrick users - it’s the default WordPress theme - I’ve created a ready-made page template that you can drop into your wp-content/themes/default/ directory.
Save this file as list-subpages.php, upload it to that directory, and you’re done.
49 Comments
Hi, this plugin is really helpfull for me, very good idea!
Does the plugin normally ad a button to the quicktags? Because in my WP 1.5.2 there is none.
Greetz, Alex
I’m afraid WordPress doesn’t offer any way to add them at the moment. It has been suggested for version 1.6, but it’s not on the feature list so it probably won’t make it unfortunately :(
I guess you can still add the button manually.
Is it a bug?
The plugin correctly lists the subpages, but the links of this list all adress to the parent-page. So all listet subpages are links to the parent page, not to the subpages!?
I don’t think that’s the way it should be?
Greetz, Alex
You’re right, that’s definitely not meant to happen. It should be fixed now - if you could download 1.1 and give me a shout as to whether it works or not, that’d be grand :)
Perfect!
Works great now!
Thanx!
Good stuff :)
Nice idea. Why not make it a bit more complete : <!– subpages –> and <!– parentpages –>, to be able to display the whole “breadcrumb” (or hierarchy) of a page ?
As for adding a quicktag button, it’s easily feasable : have a look at Owen’s plugin Edit Button Template.
Sweet, thanks for the heads up on the Edit Button Template. I’ll add that in for sure.
As for displaying parent pages, I’m not quite sure how you would want it to work. A page can only have one parent, so do you just want that displaying? Or a recursively generated list of the entire page’s hierarchy - similar to how the sidebar does it, but just related to one page?
Right, version 1.2 adds the quicktag button, thanks for that Ozh.
Still thinking about the best way to implement the display of parent items.
Not sure if you are still developing this plugin anymore, but it works, but it would be cool if you can have “a recursively generated list of the entire page’s hierarchy - similar to how the sidebar does it, but just related to one page” something they way K2 does it on the sidebar. That way users won’t have to go back to select another related page, then back again, and etc.
Rob,
I’m not sure what I’m missing, but it only works (beautifully) from a page body (a post). I can’t get it to render when I put into the sidebar … something obvious I’m overlooking?
Yep, it only works from post content. It doesn’t really work in the context of a sidebar, since a sidebar is a global thing. I guess it could detect what page you’re currently viewing, or something. I’ll have a play.
I don’t know If I have understand all, but I get it and get a sample with it, thank you!
Is there any way i can call this function from a template, instead of having to include it in the post?
Scroll up - I still haven’t done it yet, but I will get round to it eventually.
In order to get multiple levels of subpages, and to let WordPress do more of the work, I’ve replaced
with
where $depth is the desired level of nesting.
Yah, I was going to move over to wp_list_pages() at some point - thanks for doing the work for me :)
I’ll upload a new version in a sec - I’ll probably add a function you can call from a template, too.
I had a slight problem with the version I downloaded from the link above. The subpages were displaying immediately before the title “category Subpages:” and the unordered list that was supposed to contain the list of subpages. After looking at the code, I figured that wp_list_pages was executing rather than being concatenated to the html string in the list_subpages function.
So I tried replacing the echo=”.(!$return).” bit with a simple echo=0 and that seemed to work. I’m sure there’s a more proper way to fix the problem, but so far it’s working with the direct function call in my templates, although I haven’t checked if the original post tag will work properly. (I’m using WP2.0 by the way.)
Thanks for the plugin.
Hey…great plugin!
I don’t know really anything about php so I’m having some troubles. I got the plugin working but I’d like my page to show multiple levels of subpages (like you have on http://robm.me.uk/projects). How do I do this?
I tried editing the plugin code as Katja mentioned above but it didn’t work (my site was totally broken after that).
Anyway, can anyone tell me exactly how to get all levels of subpages to show? Also, is there anyway possible to have the subpages listed in two columns, instead of just one long single list?
Thanks!
Robert: Strange; PHP must interpret (!0) as
false, andwp_list_pagesonly likesints. I’ll see if addingWorks.
Kung Foodie: I’m not sure what you mean - the newest version (anything including and after 1.3) should display the full hierarchy as this site does.
I’ve no idea about the two columns idea, I’m afraid. It’ll just take some kind of CSS trickery, I should imagine.
I need to make an urgent tweak to this plugin but sadly am rubbish at php.
How can I include the current page above the list of subpages?
> Link to Parent Page
> Link to Sub Page A
> Link to Sub Page B
etc.
I can’t download the plugin.
Maybe the link is broken?
Yes the download script is broken it seems… If someone could post a temporary static link that would be great! TIA.
This is a very useful plugin. Congratulations and thanks!
I note in the comments that it seems to be possible to specify how many levels of subcategories are to be displayed by modifying the $depth variable. (See: Katja, above).
However, I don’t know enough about PHP to understand exactly how to do this.
Can you help?
I think this is a pretty sweet plug-in. As an information architect, thoguh, I am frustrated that I can’t get pages to list in WP the way they do on most standard hierarchical sites. Your plug-in works “right” (read: standardly) for the top two levels:
i can get to “my projects” in the global toolbar from anywhere.
i can see all the pages that live under “my projects”, e.g., “Plugins”
but what i feel shouldn;t be happening (read: doesn;t work this way on most sites), is that:
it’s showing all the children, no matter how nested they are.
once i go to any of the children, i lose the subnav.
the general rule for site is to list:
global nav bar
siblings of the page you’re on
immediate children (not grandchildren) of the page you’re on
so for your site, if i am on “my projects > plugins”, i feel like i should see:
the global nav (i do)
links to: Black Metal FAQ, hazeCMS, rmdir, RSS Ticker and SimpleGal (plugins’ siblings)
links to WordPress (plugins only child)
if i knew anything about php, would take a stab myself. i’m sure if i gave every level of my wp site it’s own template, i could pull this off. anyways, just food for thought!
I was gettting sub pages (I have quite a few) sorting in the wrong order, so I changed this:
$html .= wp_list_pages(”child_of=$parent_id&depth=$depth&echo=”.(!$return).”&title_li=0″);
to this:
$html .= wp_list_pages(”child_of=$parent_id&depth=$depth&sort_column=menu_order&echo=”.(!$return).”&title_li=0″);
(Added ’sort_column=menu_order&’ to the wp_list_pages string.)
Thought this migh help some folks.
I’m still getting the problem listed above (This works perfectly for top-level pages, such as website.com/graphics, but when you view such a page as website.com/graphics/stuff, it returns a list of all the pages in the graphics category, not just those under /stuff. I’ve made sure I’ve got the most recent version (1.5.2) but I’m still having this problem…
Thanks for this plugin! It really works nicely except for this problem.
I’m having the same problem as above. Is there any way to just list the subpages from that page, not the ones from above as well??? This would be great!
List Subpages is just what I need, but is there a way to exclude pages that are listed? I’m using WP-dTree for navigation, and I’ve entered the IDs of the pages I want to exclude in the menu; any way for list-subpages to read from that? If not, just any way to exclude pages from the list would be great.
Thanks for the great plugin, and I hope to hear back from you soon about my question(s).
It would be great if I could get it to work…
I added list_subpages() to my page template…
… and yes, the sub-page appear 100% correctly… however, they appear BEFORE the Parent header title. I didn’t change anything (just added that one line), so I don’t know what I’m doing wrong.
For example, let’s say you have Parent page name - “Meat” and 2 subpages: Pork, Beef. So I expect this to appear:
Meat Subpages:
Pork
Beef
Instead this always appears:
Pork
Beef
Meat Subpages:
Help, someone?
This site says latest version is 1.5.3 however, the php file I downloaded today indicates 1.5.2? Do I have the old version?
This is all wonderful, but how to display only subpages of a page that’s already a subpage of some other page?
Maria: I have tweaked the plugin page itself because I had the same problem and it works now. Want my file?
Hi Iva,
Yeah, that would be super! Please e-mail file to:
fruity AT fruityoaty DOT com
(Replace the AT with @ and DOT with .)
Many thanks,
Maria
Rob,
I’m using the WP-Andreas01 1.3 theme which contains your subpages code. I really like it. Unfortunately, when a picture is inserted into a page, the submenu heading appears even though there are no child pages. Can you assist? The site is http://www.alpineskisandboards.com
Thanks,
Rob
Just what I was looking for. Saved me some time, thanks!
i’m having problems with displaying it. the “< li >” tag seems to have gone up, rather than after the “< ul >” tag, so now the subpages are displaynig above the title. i have no idea how to fix this since i’m not much of an expert in this field. help please! :D
Preckie is right, there is something wrong in the code - li items are coming above the title. I have rooted around in the php but can’t see what’s causing this. I hope this can be easily resolved, since this looks like a great plugin.
Same problems as Preckie and Simon above. I created a custom “subpages” template, got it working in WP and then when I add the < ?php list_subpages(); ?> line and view the page, the source code looks like this:
< li class=”page_item” >< a href=”http://website.com/insert/permalink/here/” title=”Link Title” >My Link< /a>< /li>
< div class=”list_subpages”>
< h4>My Page Subpages:< /h4>
< ul>
< /div>
This appears to be a very good plugin and it DOES work using the inline syntax (< !–subpages–>) but I can’t get advanced templating to work due to the bug.
I did some digging and in the source code I modified line number 42 of the list-subpages.php file.
Original code:
$html .= wp_list_pages(”child_of=$parent_id&depth=$depth&sort_column=menu_order&echo=”.(!$return).”&title_li=0″);
Modified code:
$html .= wp_list_pages(”child_of=$parent_id&depth=$depth&sort_column=menu_order&echo=0&title_li=0″);
Note that I changed the “echo” parameter to a value of “0″ — I don’t know alot of PHP or anything, but this seems to have solved the problem. Could there be an issue with the $return variable that’s causing this bug?
Anyway, it (seems) to have solved my problem for now. I hope this helps somebody.
..k..
Kyle, if you’re using it just as a PHP call then you’ll want to modify it from this:
to this:
That’ll echo it without the need to modify the code.
I get the following error, below the header (where I put the php call function)
WordPress database error: [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'ASC' at line 1]
SELECT * FROM wp_posts WHERE post_status = ’static’ ORDER BY ASC
You put what in the header, Nicholas? You don’t need to insert any PHP code into the header to use List Subpages…
Nicholas: I was having this problem earlier, so I added the following line to the “list-subpages.php” plugin file and everything was fixed.
if (!$order) { $order='post_title'; }It should go before line 47, which looks like this:
if ( $subpages > 0 ) {Hope that helps!
Awesome plugin, btw. Exactly what I was looking for.
Typical programmer behaviour from me, editing things before I figure out how to use them. Instead of adding that line, call the function like this:
echo list_subpages('order=post_title');Having said that, it’s still useful to add that line to prevent the plugin from throwing an error if no sort query is passed.
Great plugin, but I have a quick question, how do you manipulate the output so that it only spits out the sub page link without the rest?
eg. if I have Page 1 and subpages 1A and 1B how do I get the output on my page to only show links to 1A and 1B?
Hi,
I’ve used your nice plugin for some time.
But it seemed to stop working with the latest WP version.
So I upgraded to the latest plugin version.
But inserting the [subpages /] tag (without the brackets) on http://game-research.com/index.php/articles/ I get all pages on the site, and not the subpages of the “Articles” page.
Any ideas?
Thanks.
I tried your instructions for creating a new “list-subpages.php” template, but when I go to edit a page and try to select a page template, the new template doesn’t appear in the drop-down box.
BTW, one of the things I want to do with this is create an “Acknowledgements” page to list all the plug-ins and widgets I’m using, with “reviews” of each. I’m using a couple of yours, and they’re great!
Well, it looks to me like this plugin is broken somewhat under WP2.1 — as Jonas noted on 01 Feb 07, I’m also getting a list of ALL pages on the site, rather that just a list of subpages for the page I’m currently on. Unfortunately, I don’t have time to troubleshoot this myself — has anyone found a solution?
I am using this plug-in embedded in the Chameleon theme ( http://webgazette.co.uk/web-design/wordpress-themes/chameleon/ ). This theme has a dynamic “subpages” menu that displays below the horizontal pages menu when there are subpages.
Now I have a strange problem:
1) One of my pages lists itself as a subpage. I can click and click and click and the page stays the same. phpMyadmin reveals that there actually is NO real subpage anywhere, so there’s nothing to correct in the database.
2) One of my pages lists the subpages list, but it is empty.
So maybe it is “” or ” ” or something… That page actually has a child - but it is an attachment.
Code from this plugin:
// First it seems to change $current_page to parent?
// Goes to top of page hierarchy???
while($current_page) {
$page_query = $wpdb->get_row(”SELECT ID, post_title, post_parent FROM $wpdb->posts WHERE ID = ‘$current_page’”);
$current_page = $page_query->post_parent;
}
$parent_id = $page_query->ID;
$parent_title = $page_query->post_title;
// Only display the message if there are actually subpages
if($wpdb->get_results(”SELECT * FROM $wpdb->posts WHERE post_parent = ‘$parent_id’”)) {
echo’< div id=”subpage” > < ul >< li >Subpages: < /li >’;
$html = wp_list_pages(”child_of=$parent_id&depth=$depth&echo=”.(!$return).”&title_li=0″);
echo’< /ul >< /div >’;
}
There is a bug in the conditional statement.
When a page has an ATTACHMENT, the SELECT * FROM statement returns true, and the Subpages header is displayed. wp_list_pages does not list attachments, though. –> Header and empty row. This happens in WordPress 2.0.7.
Page type = attachment should be excluded.
Better yet, include ONLY 1) “pages”, 2) that are “published”. Can I see an incompatibility with WP2.1 here in the present code? WP2.1 uses two fields now to describe the type and status of the record.
The other problem, subpage being subpage of itself, is not yet resolved.
My lament can be found here, too: http://wordpress.org/support/topic/106065
11 Trackbacks
[...] New WordPress plugin: List Subpages I wrote a new WordPress plugin today, List Subpages. Basically, it allows you to list the subpages of a static post by [...]
List Subpages
[...] t/) Tested 0.7.1 and 0.8 Links Page (http://www.asymptomatic.net/wp-hacks/) List Subpages (http://robm.me.uk/projects/plugins/wordpress/list-subpages/) LiveCalendar (http://www [...]
[...] The second plugin is called ListSubpages, and it really is very nice, as it automagically creates a list of subpages in a parent page… which makes producing directories a lot easier! Expect to see quite extensive use of this facility on this site [...]
[...] L’estensione utile della settimana WP list-subpages che permette di inserire la lista delle sottopagine di una specifica pagina usando semplicemente un tag di commento. [...]
[...] [ ] I need sub-pages to appear on pages, or in the tab menu / sidebar of pages. [ ] I could add some code from the Wordpress codex entry on Pages, particularly the template tag specification, directly to my template. This codex entry also contains information on creating custom page styles, say for our profiles or university profiles or the like. The template spec contains a code example that I pasted into a sidebar widget… however the PHP got messed up. [ ] found a plugin called Subpages, although it isn’t a widget and looks undocumented. [ ]Also found another more recent plugin, List Subpages, which I used - however note that it must be called within a page post, not a template, which is frustrating as it would need to be manually added to each page… [...]
[...] WP-Andreas01 is based on the new version of my andreas01 template (see previous post), although it is not a 100% perfect match. For example, the main menu of the theme has only one level, while sub-pages are displayed in a second menu which appear inside the pages using styles that are not included in the original template. Once again, thanks to Rob Miller for his list subpages plugin which I have included in the theme. There are also other less visible changes, but the theme is still very faithful to the look and feel of the original template. For example, the new 2-column layout is used in the theme since the third column is not used on content pages… [...]
[...] List Peer Pages PluginThis plugin allows you to list the “peer pages” (i.e. pages with the same parent page) of the current page. While there are already plugins that allow you to list the child pages of a parent page (and thus allow you to imitate the function of this plugin), they are not necessarily easy to configure to provide this function. [...]
[...] List Subpages plugin: Lists the child pages of a parent page. [...]
[...] of static pages that you want to manage, rather than just an endless number of posts. You can use a Subpages plugin in your sidebar to make it easy for your users to find the pages. The context-sensitive Subpages [...]
[...] Visit [...]