WordPress is quite versatile and easy to use, but it seems to fail in some features that should be present at its core, like the ability to list pages’ content easier. Here’s an explanation of how to use a little plugin I found recently, and that doesn’t seem to be that widely known or documented.
Me, the designer
As I’ve said here before, eve though I’m not a complete beginner, my knowledge of WordPress is fairly limited. I’m essentially a front-end person, so the less I have to dive into PHP and the likes, the better. My goal is to always find a balance between flexible code and simplicity.
If, by the end of the post, you feel this could be easily done with another technique, feel free to leave a comment.
I needed to display the list of a certain page’s sub-pages, along with an excerpt from those pages. Very simple, right?
How to use the plugin
First step: install the plugin.
The plugin uses a shortcode (
[epl]) that you can add directly into your posts, and customise with some parameters. It overrides the
get_pages() function, so you can use all of
get_pages() parameters, plus a few more.
When editing a page, you would use something like this:
But I needed to add the plugin to a template, to be used on a number of pages. The client was going to be able to edit the introductory text on each parent page, but the list of sub-pages should be generated automatically bellow that.
So I used the do_shortcode function on my template file. Its Codex page is not that useful.
This function allows you to call a shortcode and use it just as you would use it within a post (or page). So I could now do this:
<?php echo do_shortcode('[epl sort_column=menu_order showexcerpt=1 excerptlength=20 excerptmore="Read more…" morelink=1 excerpttag=""]'); ?>
As you may notice, I used many of the parameters supported by the plugin to control what was displayed on the page. That’s one of the things I love about this plugin — the flexibility. You can control everything, from the excerpt’s length, to the HTML element that you want wrapping the whole block, or each page, which CSS class to apply, etc.
And that’s all! I decided to put this little post together, since I didn’t find any documentation on how to use this plugin within a template file — the plugin’s website itself doesn’t seem to mention it. And, although it may be clear to many people, it wasn’t for me.