List Subpages With Descriptions: WordPress Plugin

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.

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.

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: 1.0
  • Requirements: Exec-PHP Plugin or some other plugin that allows you to put PHP code into your Wordpress Pages.
  • Download Plugin (22017)

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.

22 Responses to “List Subpages With Descriptions: WordPress Plugin”

  1. Trackback/Pingback

    [...] List Subpages with Description lists a Wordpress Page’s subpages in an unordered list with a description of each one. [...]

  2. Thanks!

    Just what I needed. Is there a way to disable the list on certain pages though?

  3. 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().

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

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

  6. Trackback/Pingback

    [...] more info and download…. [...]

  7. Trackback/Pingback

    [...] List Subpages with Description lists a Wordpress Page’s subpages in an unordered list with a description of each one. [...]

  8. Trackback/Pingback

    [...] List Subpages with Description lists a Wordpress Page’s subpages in an unordered list with a description of each one. [...]

  9. Trackback/Pingback

    [...] List Subpages with Description lista las subpáginas de una página de Wordpress en una lista sin orden y con una descripción de cada una. [...]

  10. Any ideia on how to get the list of sub-pages and its sub-sub-pages (children)?

    Thanks

  11. 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:
    <?php
    /* LIST SUB-PAGES (/PAGE/PAGE) */
    global $wpdb, $childID;
    $children = $wpdb->get_results("SELECT * from $wpdb->posts WHERE post_type='page' AND post_parent=$post->ID ORDER BY post_title");
    if($children) {
    foreach($children as $child) {
    echo '
    <h3><a href="' . get_permalink($child->ID) . '" title="' . $child->post_title . '">' . $child->post_title . '</a></h3>
    '; // END ECHO
    $childID = $child->ID;
    // BEGIN SUB-SUB-PAGES *******************
    if (function_exists("list_subpages_with_descriptions")) list_subpages_with_descriptions();
    // END SUB-SUB-PAGES **********************
    // ENDS LIST OF SUBPAGES WITH DESCRIPTIONS
    } // END FOREACH
    } // END IF STATEMENT
    ?>

    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.

  12. Trackback/Pingback

    [...] List Subpages with Description lista las subpáginas de una página de Wordpress en una lista sin orden y con una descripción de cada una. [...]

  13. Trackback/Pingback

    [...] WordPress Plugin - List Subpages With Descriptions - The function of this plugin is to list a Wordpress Page?s subpages in an unordered list with a description of each one. [...]

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

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

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

  17. Here is what I have now:

    get_results(”SELECT * from $wpdb->posts WHERE post_type=’page’ AND post_parent=$post->ID ORDER BY post_title”);
    if($children) {
    foreach($children as $child) {
    echo ‘
    ID) . ‘” title=”‘ . $child->post_title . ‘”>’ . $child->post_title . ‘
    ‘; // END ECHO
    $childID = $child->ID;
    // BEGIN SUB-SUB-PAGES *******************
    if (function_exists(”list_subpages_with_descriptions”)) list_subpages_with_descriptions();
    // END SUB-SUB-PAGES **********************
    // ENDS LIST OF SUBPAGES WITH DESCRIPTIONS
    } // END FOREACH
    } // END IF STATEMENT
    ?>

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

  19. how do you post to subpages?
    is there a way to post to subpages like you post to the main page?

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

    <?php
    // List subpages (/page/page)
    global $wpdb, $childID;
    $children = $wpdb->get_results("SELECT * from $wpdb->posts WHERE post_type='page' AND post_parent=246 ORDER BY post_title");
    
    if($children) {
    	foreach($children as $child) {
    	echo '
    	<h3><a href="' . get_permalink($child->ID) . '" title="' . $child->post_title . '">' . $child->post_title . '</a></h3>
    	';  // End echo
    	$childID = $child->ID;
    
    	// Begin sub-subpages
    	if (function_exists("list_subpages_with_descriptions"))
    		list_subpages_with_descriptions();
    	// End sub-subpages
    	// Ends list of subpages with descriptions
    	} // End foreach
    } // End if statement
    ?>

    Matt
    Yeah, that might help out. Just change this line to look like this:

    global $wpdb, $childID, $post;

    mgmt
    You might want to check out WordPress Pages.

  21. Sorry to ask the obvious question, but does the plugin work with 2.5? Thank you!

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

Leave a reply

Log in or Register



XHTML: You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> 
<blockquote cite=""> <cite> <code> <del datetime=""> <em> 
<q cite=""> <strong>