SB Child List

Here’s the story:

I wanted to show some sort of hierarchy in the pages inside WordPress. I decided to call one of my pages ‘articles’ and have my articles use it as their parent.

Logically you would expect to see a list of the child pages on the articles page along with a pretty picture and some intro text. This doesn’t seem possible natively with WordPress so I decided to make it happen.

Adding the hook to any post or page will by default show an unordered list showing the children and links to them. If you prefer to style it yourself then don’t worry because you can do that too using the templating system on the settings page.

There is also add another tag, , that allows you to provide a back to parent link from any child. This enables you (in the articles example) to add a “click here to read more on this subject” link. It is also template based so it can say anything or look however you see fit.

Latest version is in the WordPress Plugin Directory here: http://wordpress.org/extend/plugins/sb-child-list/

Download an old archive version here (V1.0): SB Child List (3.05 kB)

Example Site

I wrote this plugin so that I could display articles in a hierarchy on my boat site (Still in development). See examples of how I am using it at http://boathook.sean-barton.co.uk on the articles page. I have updated the CSS to fit it in with the rest of the site.

Screenshots

Example shortcode hook usage

Shortcode hook usage

Example Page Tree

Example Page Tree

What it all looks like (Default)

What it all looks like

77 comments

  1. Mike says:

    I started a new wordpress site. I liked your plugin and worked great. I had installed and tested it in a sub-directory and now want to implement it by simply redirecting the domain to that subdirectory. Everything works great except this plugin which when it lists the child names, still includes the old directory, which no longer exists. Is there a way to get it to re-calculate the list?

    • Sean says:

      Hi Mike,

      The plugin doesn’t store any paths, it simply used the guid field in the wp_posts table. That is updated by WP itself. To sort it often it only takes a single edit to the page itself which should update the path. So visit the edit screen for the page in the admin system and click update page which I think will sort it. It’s a common problem I have heard of as WordPress for some reason doesn’t often update those fields. There must be a way to force a mass update? Let me know how you get on.

      thanks
      Sean

  2. Luke says:

    I’m having precisely the same problem. Scoured the database manually and cannot determine why sb_child_list is displaying the original installation’s post_permalink value instead of the new one. Absolutely mystifying.

  3. Sebastian says:

    Hi,
    Maybe I got the solution for your problem:
    The hook “[post_permalink]” refers to the “guid”-field in the table “wp_posts”. When a page is created the url is written to this field, but it won’t ever be updated – for example if you move the pages to another domain..
    My solution was to update the sql-table in phpmyadmin or to insert my own “[post_name]” hook in seans plug-in…

    greetings from zurich,
    sebastian

    • Sean says:

      Hi Sebastian, I’m not entirely sure the fix is relevant to my plugin although please do elaborate on the need for the post_name hook. I am looking into a way to get the proper permalink to show.

      Suggestions welcome.

      thanks
      Sean

  4. Same issue here: permalink not updated, so all my link go bad if I change any permalink.
    Changing the title of the post is not an issue but:
    - moving a page
    - renaming the permalink

    Both result in the wrong link.

    I suppose the two “->guid” in the plugin must be changed to get the real permalink, but I do not know which filed should be used…

    Sebastian, woudl you mind sharing the info on which filed you used to create your own hook?

    • Sean says:

      Hi Sebastian,

      I used the guid field from the wp_posts table which I assumed would work but obviously not :) Try updating the code to user get_the_permalink() instead of $post->guid.

      thanks
      Sean

  5. Jon says:

    Sebastian,

    Is is possible to add thumbnails of images to the child list? I already have another plugin that is using a custom field that utilizes thumbnails created with the field called “thumb”. Is there a way to insert these thumbnails into the list?

    • Sean says:

      Hi Jon,

      Yes there’s no reason why not but then you would need to edit the code to suit. Look for the sb_cl_render_child_list function around line 128 in there and inside the loop (foreach ($children as $i=>$child)) just add a new str_replace line for your thumbnail around the $template = str_replace(‘[post_title]‘, $p->post_title, $template); section making sure to change the template name and values accordingly. Obviously you would need to use the PHP function to grab the thumbnail and then add it in but it will be a ten minute job. If you want a hand doing it then get in touch.

      thanks
      Sean

  6. Vignan Tej says:

    Hi Sean

    I’d like some help in adding Thumbnail and an content in the child pages loop.
    I am a newbie and am just good at copy-pasting stuff. Could you please help me out with the code to be put around $template = str_replace(’[post_title]‘, $p->post_title, $template); section.

    I just want it to be displayed like:

    1st Child Title
    Thumbnail
    Content

    2nd Child Title
    Thumbnail
    Content

    And so on…
    Help greatly appreciated :)

    • Sean says:

      Hi Vignan,

      Thanks for your comments. I have just added the ability to have post thumbnails this evening thanks to another plugin user. If you wait until the plugin updates on the directory overnight then download it you will be able to use the new hook [post_thumb]. just update the template to put the hooks in divs and it should work.

      Let me know how you get on.

      thanks
      Sean

  7. Is there a way to only show thumbnails for a given list, rather than for all lists throughout the site?

    • Sean says:

      Hi, currently not although of course if you don’t add the thumbnail to a post then it won’t show. I shall add shortcode arguments for a future version for you.

      thanks
      Sean

  8. Mark Barnes says:

    I’m getting the error
    Fatal error: Call to undefined function get_the_post_thumbnail() in /home/blog/public_html/wp-content/plugins/sb-child-list/sb_child_list.php on line 166

    This is with WordPress 3.01. I “fixed” it by commenting out the offending line.

    • Sean says:

      Hi Mark,

      Yes sorry about that. I added the code and of course it worked for me having the appropriate plugin but I overlooked the fact that it wouldn’t work elsewhere. I have fixed it for the current release so shouldn’t happen any more.

      thanks
      Sean

  9. Chris says:

    Sean,

    what was the name of the plugin that you overlooked. I’m getting this error with another plugin.

    Thanks!
    Chris

  10. Hi,

    A great and simple plugin, I have but one request. I use it to display the text “Pages in this section:” followed by the list.

    Where there is more than one level of pages (grand-child pages), it would be great to be able to disable the “header” so I didnt get “Pages in this section” again at the top of the grand-child tree.

    Thanks for the great plugin,

    jamesakadamingo

  11. Hendrik says:

    Very nice plugin. Exactly what I needed :)

    Sean, is there a way to show an excerpt of the child pages? If so which short code?

    Thanks

  12. Micha says:

    You updated the code to display the right permalink to the child (instead of guid), but you forgot to do the same thing with the [sb_parent] tag ;) Did it myself, but just FYI, if you ever update this again, you should probably include it.

  13. Rich says:

    Sean, great plugin. My only wish is that rather than the child page list appear in a seemingly random order, that they list alphabetically. Is there a way to do that? Or could it even be made the default? I don’t write code so I’m hoping there is an “out of the box” solution. Thanks!

    • Sean says:

      Hi Rich, Thanks for the comment. The pages are ordered by menu order and then post order. If you go into each page and set the order using the box on the right hand column then they will reorder accordingly. If they are all the same then it should be alphabetically. Get in touch again if it’s not working as intended and I shall try and work the issue out with you.

      thanks
      Sean

  14. Staipa says:

    Hi! It is a great plugin, but isn’t possibile to insert it in a widget?
    I would use it for make a contextual menù…

    • Sean says:

      H Staipa,

      Thanks for the feedback. You should be able to add it into a widget… if you use the shortcode in a text widget then it should generate it as expected. How did you expect to use it? I can look at the code and make the changes appropriately then…

      thanks
      Sean

  15. Gordon says:

    Quick question – there is a post-excerpt tag in the template – where is this grabbing the excerpt from? How do I set this text.

    Thank you.

  16. Gordon says:

    I answered my own question – I thought I had excerpts filled in, and I didn’t – now it works…

    How do you order the pages though?

    • Sean says:

      Hi Gordon, glad you worked it out. you can reorder the pages using the WordPress page order feature. It’s down the bottom right of the page editor screen where you select your template usually.

      thanks
      Sean

  17. gray ayer says:

    I understand that I can change the order of the pages so that they show up according to either how we set them via the “page order” system, which is actually quite unwieldy, or whether I can leave them all as page order “zero” which will then order them alphabetically.

    Is there a way to order it chronologically, so that the most recent articles show up at the top?

    • Sean says:

      Hi Gray, thanks for your comment. Yes you can indeed change the ordering or pages but it’s a little backwards. Does the trick though. I tend to do mine in blocks or 10 or 50 so I can squeeze extras in here and there.

      Re your question on date… you have two options really. Edit the plugin file around line 210 and swap ‘menu_order, post_title’ with ‘menu_order, post_date’ or download the version I just checked in and add order=”post_date” to the sb_child_list shortcode you are using. Hopefully that makes sense. Let me know if it doesn’t.

      thanks
      Sean

  18. Mimi says:

    This is awesome!

    Above you mentioned that the shortcode could be added to a text widget. This does not work because if the page has no children, then it still displays the title of the text widget (ie. “In this section”) followed by no links at all. It would be AWESOME if you could make this into a widget that would simply not display at all if the current page has no children. I’ve been looking for something like that forever.

    Great job, thank you!

    • Sean says:

      Hi Mimi, Glad you like the plugin! I know what you mean about the widget idea so to make things easier I have just added a widget to the plugin for you to do the same job. It includes a little optional intro (supports HTML) in case you want people to see more than just the list of links. The title is optional too so you can just have the list if that’s what you want. Take a look and let me know if it’s what you wanted. I am more than happy to add widgets for you or added functionality, just let me know.

      thanks
      Sean

  19. jim says:

    Hi Sean,

    I have been searching for something like this for a while and am glad to have this now..but there is something i need to ask you..is there anyway i can expand and collapse the categories,which include my sub-categories and other pages..

    Thanks in advance,
    Jim

    • Sean says:

      Hi Jim, Glad you like the plugin! I think what you are asking is how to build a child list tree with dynamic elements to slide in and out on click? Am I correct in this? You can just add a bit of jQuery to do that for you. Using my plugin you can show infinite levels down or just a limited number so you should be able to customise it to suit. Let me know if this makes sense or if I have missed your point.

      thanks
      Sean

  20. jim says:

    Hi Sean,

    I think you are right..i want a “+” and “-” button before a category name and when i click on it,the sub-categories should show up.
    eg of the button…http://howto.caspio.com/wp-content/uploads/expand-and-collapse-button-images.gif

    I would be glad if you could help me out on this as i dont have much programming knowledge..maybe i would be able to do something if you could direct me..

    Thank You,
    Jim

  21. adam says:

    Hey Sean,

    Big problem with the plugin. The widget automatically changes the Title to either 1, 2, or 3 (depending on the chosen template) regardless of what text add to the Title text input.

    Sort of strange, but I can’t use the plugin because of it. I hope you can fix it because I like the plugin.

    thanks.

    • Sean says:

      Hi Adam,

      Glad you like the plugin. Can I ask which version you are using. I just realised the first version is linked to from my blog but I moved it to the WordPress Plugin Directory a year or so ago. The link is here: http://wordpress.org/extend/plugins/sb-child-list/

      Can you let me know which version (downloaded from me or the WordPress link above) and then I can help you further.

      thanks
      Sean

  22. jim says:

    Hi Sean,

    I really need ur help this time in fixing this..if u cud take a look at this page,u would understand what exactly i want..http://www.cashington.com/income/..i want the “Find a better paying job” to come up only when i click on an expand/plus button placed just before the title “Jobs”..i have tried a lot and i cant find anything that would help me..i would be really glad to hear from u..

    Thanks,
    Jim

  23. Sean says:

    @adam: I have just fixed this and checked in a new version. Please see the version checker on your site for the fixes.

    @jim: Sorry I’ve got back from my month long holiday to a huge pile of work. I can help if you have any budget for it in the short term however it might be a while before I can do it for you otherwise. I did, however, find this blog post which you might find useful?

    thanks
    Sean

  24. Lou Anne says:

    Thanks for the GREAT plugin. I think a great addition would be [sb_sibling] and offer all siblings in menu order or just the next sibling in menu order. That would add a serial page function to the plugin.

    • Sean says:

      Hi Lou Anne,

      Thanks for the feedback. I have just updated the child list plugin to fall back to siblings when children don’t exist. I think I need to add the explicit sibling widget and shortcode but hopefully this will be a start. Let me know what you think.

      thanks
      Sean

      • Lou Anne says:

        Hi Sean,
        Thanks for your reply and effort. I seem to be having problem when I display the grandchildren on a child page. I get this:

        grandchild 1
        grandchild 1
        grandchild 2
        grandchild 3
        grandchild 2
        grandchild 1
        grandchild 2
        grandchild 3
        grandchild 3
        grandchild 1
        grandchild 2
        grandchild 3

        Should be:
        grandchild 1
        grandchild 2
        grandchild 3

        Sorry, I can’t send you a link because it’s a member only site.

        • Lou Anne says:

          Sorry, the indents didn’t display to make that more easily seen by you. But just know that when I use the shortcode to show grandchildren it’s not working right.

          • Sean says:

            Hi Lou Anne,

            My apologies. It worked fine for me but then I had the default nesting level set to 1. I have since fixed it and checked in the next version.

            By all means let me know if you find anything else or can think of any improvements.

            ta
            S

      • What I want is to have the shortcode at the end of pages that will link to the next page in the menu item.

        • Sean says:

          Hi Lou Anne, check out the latest version that I just added to the WordPress repository. It contains two new shortcodes [sb_sibling)_next] and [sb_sibling_prev] to provide linking between child pages. Let me know if this works for you or if you want something else adding. More than happy to help.

          thanks
          Sean

  25. Thanks Sean,
    I just dropped something in your donation bucket; paypal from simplifun.com

    Lou Anne

Leave a Reply