This is my very first WordPress plugin! It’s a very simple plugin, and I made it mainly for use on my blog.
The function of this plugin is to list a WordPress Page’s subpages in an unordered list with a description of each one. Here’s an example of what it might look like:
- Link to subpage
This is the description of the subpage. - Link to subpage
This is the description of the subpage.
How to use this plugin
The instructions for using the plugin are now located in a file named readme.html within the plugin folder.
This is fairly straightforward. When you write a subpage (child page), you assign a Key in the Custom Field of Write Page to “description.” You assign that Key (description) a Value of whatever you want — describe the Page.
In the parent Page, you call the PHP function list_subpages_with_descriptions(), and it will list all subpages for that Page and their descriptions that you gave them.
Why I made this plugin
The reason I made this plugin was because I was getting tired of hand-coding every subpage and it’s description. I couldn’t find any other plugins that provided me with a way to list the description with them. So, the “List Subpages With Descriptions Plugin” was born. You can see a slightly modified version of it in action on my Writing page. The listing is the same.
Plugin Information
- Description: Lists the current page’s sub pages and the description of each subpage.
- License: GPL
- Version: 0.2
- Download Plugin (2556)
Since this is my first plugin, it is simple. Something similar has probably been done before, and the programmers have moved on to bigger and better things. This works great for my blog. It should be useful if you have lots of subpages. There’s only one line of code you have to implement.
I’m still a newbie at this, so feel free to voice your concerns and/or praises. Feel free to do whatever you like with the code, or help me make it more flexible. Leave a comment telling me how it works or if you have any problems or whatever.
Please don’t use the comments or my contact page to ask support questions. Use my support forums at Theme Hybrid, which is where I handle all support questions for my WordPress projects. Feel free to report any bugs you come across though.
Thanks!
Just what I needed. Is there a way to disable the list on certain pages though?
You don’t have to use the plugin on those pages. In order to list the subpages, you must call the function
list_subpages_with_descriptions().Right, but i thought i had to put the line in my page template:
Or is there a way i can include that into the specific page i want? If so, how do I add it?
I suppose it might work in the page template. Of course, I wouldn’t know how to control it at this point since the plugin is in a very early stage.
Here’s how the process works:
For your subpages (child pages) you need to give it a key named “description.”
You then give it a value of whatever you want to describe it as.
For the Parent Page, you just call the function right there in the “Write Page” box.
You must be able to use PHP in your Wordpress Pages for it to work this way (see requirements).
Just read the “readme.txt” file or open the “list-subpages-with-descriptions.php” file to see how to call the function.
This isn’t the greatest plugin right now, but it does what I want it to do. In the future, I’m sure there might be some better admin panel control or something.
Any ideia on how to get the list of sub-pages and its sub-sub-pages (children)?
Thanks
Yes, I’m actually doing that on my Writing page (if you want to see it action). However, since it’s not implemented into the plugin yet, you’ll have to do some coding of your own.
Here’s what mine looks like:
It’s basically the same code. The only difference is
$child, $children, and $childID. The plugin already has an if statement ready to pull in the$childID.What this does is list all of the Page’s sub-pages, then lists every one of the sub-pages’ sub-pages. Of course, it lists their descriptions also. I’m sure I’ll get around to implementing this all into a plugin one day. Since I’m no great PHP programmer, this will take a while.
One final note: I didn’t give my sub-pages descriptions on my Writing page, but I gave all my sub-sub-pages each a description.
I hope this helps.
dear justin, i tried to use your code for listing pages/subpages and subpages. I doesn’t wordk. Do I have to put the code in the parent page? But do Ihave also call the function or not? I didn’t really undestand very well this code. Tnx. Carletto Genovese
I get an error with the code also:
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 'ORDER BY post_title' at line 1]
SELECT * from wp_posts WHERE post_type=’page’ AND post_parent= ORDER BY post_title
I fixed it by changing this line:
$children = $wpdb->get_results(“SELECT * from $wpdb->posts WHERE post_type=’page’ AND post_parent>0 ORDER BY post_title”);
It works, but I have no idea if it is correct since this is the first bit of PHP I have looked at, though I do know SQL.
Whoops, my first stab at PHP wasn’t correct. Here is something that works better at least. Add this under the third line:
global $post;
As I understand it, the $post object has to be declared as global here.
Here is what I have now:
Deleted by admin. Please properly post code.
Hmmm… the listing I tried to post above didn’t come out complete. In any case, the only change needed to Justin’s code in comment #11 is to add this below the third line:
global $post;
how do you post to subpages?
is there a way to post to subpages like you post to the main page?
charliegolf
If you want to list a subpages’ subpages, then just use the code below. Paste it directly into your main parent page. So, the code goes into the first-level page. It displays a link to the second-level page with a list of links and descriptions of the third-level pages.
Matt
Yeah, that might help out. Just change this line to look like this:
mgmt
You might want to check out WordPress Pages.
Sorry to ask the obvious question, but does the plugin work with 2.5? Thank you!
The plugin download link isn’t working, but thank you for providing the code in the comments. I’ve decided not to use the plugin (hassle of turning of WYSIWYG for Exec-PHP) and instead create a brand new page called page-reviews.php with the code in comment #20. Thank you so much!
As usual, you’re being absolutely brilliant!:)
That might be a not-so-automatic plugin, but some of us like it that way.
Now, I was wondering two things, since I’m not that great with PHP.
I have managed to hack the php file to change some of the classes’ names and make the entire blocks clickable and I quite like the way it looks. My site is too confusing and the subnavigation is, at the moment, the ugliest thing in the known world and this will help it a lot once I launch its new version.
However, I
If I, let’s say, have a custom field for the subpage thumbnail and I would like to
I would also to write down the time when the page was last modified ( this: http://codex.wordpress.org/Template_Tags/the_modified_date); where do I implement that in the code? I tried to add php codes for each without , but it resulted in an epic fail.
This is my modification and let’s say that I intend to put those two in the places I’d bolded:
Deleted by admin. Please properly format code if posting here.
Oh, by the way, I do realise that I could put both inside of the description field and enable php code on each single subpage, but I asume there IS an easier way?
Also, is there a way not to display pages alphabetically, but in the specified order?
Sorry for all this, I’m playing around with the plugin and noticing things along the way.
Here’s a link to the code as a text file, as putting it amongst code tags obviously did not work properly (for which I am honestly sorry):
http://www.squirrelism.net/example.txt
Iva
If you need help with any plugins or tutorials here, feel free to stop by my support forums.
Honestly, I haven’t touched this plugin in ages though, so I’d have to take a look through the code.
Thanks, will do.:)
Dear Justin, I used your script and now it works perfectly. Just want to know another thing. If i have lot of subpages and I want to list them max 10 subpages per times what can I do to let me show just only 10 subpages and the other 10 or more in another pages. Tnx a lot. Charliegolf
Everyone, the plugin has been update to version 0.2 after being dormant for almost two years. There are many more options and even a shortcode you can use.
Aunque no pude aun hacer andar aún la descripción de las sub-páginas me parece que es un muy buen plugin, busqué algo asi por mucho tiempo, muchas gracias.
Felicitaciones.
(Congratulations and thanks from Argentina)
This is very useful! How can you get the list to display according to the menu order?
You might also look at my AutoNav plugin, which lets you list child pages in a list, or in a table of thumbnails (each thumbnail being associated with a subpage either through its attachments or through a specified image).
http://wordpress.org/extend/plugins/autonav/
Thanks for the plugin, solved days of trying to figure why archive pages weren’t showing child pages very well, and with very minimal installation.
Hi Justin, Thanks so much for this great plugin. I’m using it in the sidebar of a site. How can I get the current_page highlighting feature to work to indicate that I’m currently on one of the subpages. Thanks so much in advance for any ideas.
Is this case possible ?
Page title
Image (external image link)
Excerpt(WP’s excerpt)
*title, image order is O.K if any order.
* currently, subpage is O.k(in Text)
How call & insert external image link with excerpt sub list, could you give good idea?
Tks
also, when call & insert external image, how resize images?
Tks in advance
Perfect, exactly what I was looking for
Exactly what I needed, a 6 year old plugin
Still works on WP 3.5 °_°
Thanks a bunch!