Subpage Listing

About

Subpage Listing is a WordPress plugin that allows people to take full advantage of WordPress Pages’ hierarchy by generating a navigational tree of the pages below them (subpages).

For example, say you have a parent page called “Parent.” Now, say you have 3 pages under “Parent,” called “Child1,” “Child2,” and “Child3.” Now, say that you have 2 pages under “Child2″ called “Grandchild1″ and “Grandchild2.”

Subpage Listing would create a navigation tree for “Parent” that looks like this:

  • Child1
  • Child2
    • Grandchild1
    • Grandchild2
  • Child3

This allows you to very easily create a complex hierarchical structure that can be browsed.

Download

Usage

Blank pages will automatically be given a navigation tree. This allows you to quickly create “container” pages (all you do is fill in a title, and choose the page’s parent.)

If you would like to insert the navigational tree manually (that is, surrounded by text of your choosing), use the “Subpage Listing” quicktag that will show up on the Write Page screen. This will insert the tag: <!--%subpages%--> which will be replaced by the listing of the subpages.

Note: when inserting the tag manually, make sure that there is a blank line both above and below the tag, so as to ensure proper handling of your surrounding paragraphs by WordPress.

Update (version 0.6)

Version 0.6 is a massive update that adds a bunch of new functionality. The ability to show the current page’s parent has been added, as well as the ability to show the current page’s siblings. You can also supress the showing of children, and show only siblings, parents, or both. To use these features within a post, use this syntax: <!--%subpages(5,1,1)%--> The first “parameter” is the depth you want to show. You can set this to 0 to suppress display of children. The second “parameter” is a boolean switch for display of the parent page. The third “parameter” is a boolean switch for display of sibling pages. All are optional, although if you want to set the second “parameter”, you also have to set the first, and if you want to set the third, you have to set all three.

There is also a new function for use in your templates. Many people wanted to show subpages or siblings in their sidebar, so now you can do that. <?php txfx_wp_subpages(); ?> is the most basic form, but it can take many parameters. <?php txfx_wp_subpages(5, false, false, '<ul>', '</ul>', true); ?> will show 5 pages deep (first parameter), hide the parent (second parameter), hide the siblings (third parameter), wrap the whole thing in ‘<ul>’ and ‘</ul>’ (fourth and fifth parameters), and will echo the result (sixth parameter). These happen to be the default settings, that I have just illustrated.

Please let me know what creative uses you come up with for this plugin by leaving a comment below!

Versions

  • 0.6.1 Fixed a bug regarding dollar signs being interpreted as preg backreferences
  • 0.6 txfx_wp_subpages() function, <!--%subpages(5,1,1)%--> style of tag within posts, ability to show parents, siblings. Big thanks to Scott R. Godin for feature suggestions and beta testing on this release
  • 0.5 Internal release
  • 0.4 Changed the JavaScript that inserts the quicktags. Update if you were having problems with that.
  • 0.3 Initial public release/

I’ve spent a lot of time writing this code and supporting it. If you derive some benefit from this code, please consider showing your gratitute in a more tangible
way. Thanks!

I have received $0 this month for my coding efforts.

Donate with PayPalAmazon.com Wishlist


68 Responses to “Subpage Listing”

  1. FilSchiesty |

    Sounds good Mark, but download link is a blank file.

  2. Mark (post author) |

    Grr… thanks. That’s what I get for relying on an external service to package the zips for me. I just did it manually for now. Gotta write some code to do SVN checkouts and generate zip files automatically.

    Link should work now.

  3. Darrell Schulte |

    Like this plugin, Mark. Nice work. Any trick to getting it to appear in the sidebar?

  4. sami |

    Thanks Mark, it helps me to arrange childs (chapters) of my e-book. I’m working on : http://www.fikra.kitab.nl/?page_id=15

  5. ovidiu |

    hi there,

    is there a way to influence the order of appearance in a subpage listing?

    to me it appears as if the subpages are ordered alphabetically, isn’t it?

    cheers
    ovidiu

  6. Usayd |

    Nice, I use Navigo which I think gives you more options, ovidiu I think it has support for that too.

  7. Scott R. Godin |

    line 51 of the script, the final <ul> should be <ul class=”children”> in order to properly control via css the resultant sub-pages for display. Discovered I’d ‘fixed’ this when I upgraded to 0.6.1 from the original. Thought you might want to know. :-)

  8. Justin Moore |

    Is there an easy way to suppress the subpage listing on top-level pages? Otherwise, this is perfect so far!

  9. Iva |

    Would it be possible to change the way listed subpages are sorted? E.g. I’d like to sort them alphabetically by their slug.

  10. Cris Bloomfield |

    PSA: Anyone looking for Chris McCaffrey’s Wordpress list_peer_pages.php script recently won’t have been able to find it as it appears his website is offline.

    I think that the solution people looking to use this plugin provides has been solved elsewhere. Consider this example:

    If the page structure for the website is as follows

    Page A
    - Child A Page A
    – Grandchild A Page A
    – Grandchild A Page B
    - Child A Page B
    - Child A Page C
    Page B
    Page C

    When in one of the grandchild pages I want to be able to see all the grandchild pages.

    Now I need the menu to be dynamic, so I can’t just statically address the pages. In my mind I would describe this as wanting the navigation menu to show the peer pages to the current page aka the brothers/sisters aka the siblings.

    i.e. the navigation menu will show

    – Grandchild A Page A
    – Grandchild A Page B

    when you are looking at either Grandchild A Page A or Grandchild A Page B.

    The means to do this has been provided by Kafkaesqui over at http://wordpress.org/support/topic/89781. Basically used this code:

    post->post_parent) ) {
    $parent = $wp_query->post->ID;
    } else {
    $parent = $wp_query->post->post_parent;
    }

    wp_list_pages(”title_li=&child_of=$parent”);

    } ?>

    Hope that helps some one else!

    Cris

  11. Cris Bloomfield |

    Er…

    it didn’t like that PHP code did it ;)

    Here’s a link to the plugin.

    http://media.stars.manchester.ac.uk/webdev/wp-plugins/list_peer_pages.zip

  12. Chris |

    Is it possible to use this plugin and then list the pages in menu order? I can’t seem to escape pages being listed alphabetically with this.

    Thanks.

  13. yoyo |

    I want to display the subpages in menu_order too!

  14. Jennifer |

    For everyone asking whether the ordering of subpages can be changed, the answer is yes- if you are willing to change a bit of code in the plugin.

    To list your Pages in the order defined by the Page Order setting in the Administration > Write > Write Page panel, you have to modify the code in the plugin:

    1. From your Wordpress admin page, click on “Plugins”.
    2. Next to the “Subpage Listing” plugin, click on “edit”.
    3. Find this code:


    if ( $show_siblings ) {

    $siblings = wp_list_pages('child_of=' . $post->post_parent . '&depth=1&echo=0&title_li=0');

    4. Did you find it? Good. Now replace this:

    '&depth=1&echo=0&title_li=0'

    With this:

    '&depth=1&echo=0&title_li=0&sort_column=menu_order'

    And that should do it.

  15. deKay |

    I’ve installed this plugin today (WP 2.1.2) and am using a slightly modified The Porters theme (just colour and graphic changes, no layout). Unfortunately, the “txfx_wp_subpages()” bit (in the sidebar in php tags, obviously) does nothing. At all.

    Where can I start looking at what is wrong? I’m using v0.6.1 of the plugin.

  16. Dennis |

    The first thing I wanted to make it do was make it sortable by page order rather than alphabetically. While it was pretty easy to edit the wp_list_pages line to fix it, it’d be nice to have it configurable.

    I was halfway to hacking in another flag to make it sort by page order on demand when I realized it would be easier to just add the entire sort order field as a parameter, allowing any type of sorting by the user.

    So there it is.

    I’m also looking for a function to not just list child pages of a page, but to actually insert them. So if you have a blank page, you add the tag and they get included.

    The utility of this is to build a technical document in sections and have the sections expand and collapse within the higher level page.

    But I’ll probably just write that stuff.

  17. Lorin Rivers |

    I couldn’t get this to work either. I put the tag into the content area of my page template and it just acts like a comment.

  18. Marc |

    I’ve put in the wp_list_pages vars to sort by menu_order but my menu still comes up in alpha order instead of menu_order. I’ve changed each of the page order numbers to be consecutive but the list order doesn’t change. Any help?

  19. angellica2017.com |

    It doesn’t works on my site. Would you please fix the bugs for this plugins. I still receive many errors on my site when implementing this plugins.

    Regards
    http://www.angellica2017.com

  20. www.angellica2017.com |

    Forget it… I did it.
    The subpage already shown… :)

  21. Steven Vu |

    I love your plugin although it misses a vital function.

    Page A
    - Child A Page A
    – Grandchild A Page A
    – Grandchild A Page B
    – Grandchild A Page C
    – Grandchild A Page D
    – Grandchild A Page E
    – Grandchild A Page F
    - Child A Page B
    - Child A Page C
    Page B
    Page C

    When viewing Grandchild A Page A you can view it’s siblings and the parent but you can’t view the page you’re on. While it might not seem logical at first to be able to view the page you’re on, when in use the menu jumps.

    When on page C

    – Grandchild A Page A
    – Grandchild A Page B
    – Grandchild A Page D
    – Grandchild A Page E
    – Grandchild A Page F

    When on page E

    – Grandchild A Page A
    – Grandchild A Page B
    – Grandchild A Page C
    – Grandchild A Page D
    – Grandchild A Page F

    It’s very easy to lose track of what page you’re viewing. An example is here: http://testteachtuition.com/11_plus/free-practice-papers/city-of-london-school-for-boys/

    I can offer recompense of 10 sterling pounds if you’re willing to do it within a week.

    Regards,
    Steven Vu

  22. NBoy |

    WP 2.2 runs fine with this, I have used the following in my template

    ‘, ‘‘, true); ?>

    I also have the same issue, the plugin works 99.99% exactly as I need, apart from the fact that it hides the current sibling in the sibling view just as Angellica said above.

    I’m gonna have a look at the code, but I’m no real PHP coder! I presume you have coded the function to hide the current sibling, so it basically functions as ‘when viewing sibling, display all siblings of parent EXCLUDING current page’.

    If you (or anyone else) has any suggestions on how to fix this, it seems we would both be very greatfull!!

  23. NBoy |

    Whoops, my code didnt come out right at all, please ignore it! I have not solved the issue yet, man I wish I could get it to always show all siblings and not exclude the one currently being viewed.

  24. youtube |

    Great plugin, only one issue for me: Using WP 2.0.5, on the search results page it says “Search Results for:(blank)” where (blank) should be the terms searched for.

  25. indir |

    I’m a real newbie with WordPress, as i am with most of the internet, but I’m going to give this a go. I’ll let you know how I get on with it.

  26. Steven Vu |

    I’m using your plugin to order 250 pages or so. I couldn’t get the current page to view inside your list so only showed your list a level above. That coupled with a breadcrumb plugin I found means it’s quite usable.

    The real problem i’m having at the moment is getting the pages to list using the page_order that you set. The fix you mentioned above doesn’t work i’m afraid.

    Sure you can’t fix this? i’ll give your 10$ and all the love in the world.

    Steven

  27. Steven Vu |

    I think I’ve managed to get page_order to work. Change this:

    if ( $depth > 0 )
    $subpage_text = wp_list_pages(’child_of=’ . $post->ID . ‘&depth=’ . $depth . ‘&echo=0&title_li=0′);

    to
    if ( $depth > 0 )
    $subpage_text = wp_list_pages(’child_of=’ . $post->ID . ‘&depth=’ . $depth . ‘&echo=0&title_li=0&sort_column=menu_order’);

    Seems to work fine. Thanks for the wonderful plugin.

  28. www.yosax.com |

    errrrrr….. didn’t working!

  29. wawan |

    how to make sub pages view only at pages that we want. Not all of parent that have sub pages will display. Thanks before

  30. Nikola |

    i just donate some money for your coding man and than`s for sharing with us

  31. Odilon |

    Hi, how could I customize the css by adding a class parameter to the UL or LI’s?
    The code being now generated has a different LI class for each element, being generated by each and every page ID, and so that’s impossible to match a css onto them.
    Any help appreciated to help me force the generated code to use only one ul or li class for all pages.
    TIA,
    O.

  32. Alex |

    Thought I’d buy you a beer for your coding efforts. This helps a lot. Thanks!

  33. eric |

    hi Mark,
    I’ve just installed your plugin (WP 2.3.3) and it works fine.
    I ve looked for this solution since months.
    Many thanks.

  34. azlio |

    The plugin is working fine!

  35. cexut |

    Ow, what a great plugin.

  36. Kevin Dykes |

    Hi Mark -

    Enjoyed meeting you at WordCamp Dallas this year. Curious if subpage plugin works well with 2005?

    Thanks

  37. Mark (post author) |

    Kevin, I’ve had no problems!

Leave a Reply