Two Display Posts Tricks

I’ve been a fan of Display Posts since the days of straight Non-Programistan. Despite the fact that I can write my own stuff from scratch, Display Posts still comes in handy all the time. The following are just two little tricks used in a recent course site. I’m just skimming the surface of the capabilities of the plugin but hopefully it shows you how a plugin like this can do some of the non-standard display work that makes faculty happy and creates a site that has custom capabilities without the overhead of a custom theme.

Origin Story

We had a quick turn around for a faculty member who is teaching a class on the Climate Crisis and he wanted two non-standard display features.

Image Widget Based on Post Featured Images

Initially he set up an image album in the sidebar as a widget but updating that was going to be manual and that’s a pain. With Display Posts I can make a quick shortcode (pretend it’s in square brackets1) that gives us the featured images of the 5 most recent posts but doesn’t include the titles or any content. A dab or two of CSS and you’re good to go.

[[display-posts include_content="false" wrapper="div" image_size="medium" posts_per_page="5" include_title="false"]]

Full Content of Most Recent Post, Excerpts of Subsequent Posts

For the weekly information for students, he wanted the most recent post to show the full content. Below that he wanted the title and excerpts of the older posts to be visible.

We can do that with two shortcodes which we’ll put together on one page.

We’re getting only one post with the first one (posts_per_page=”1″) and getting all the content (include_content=”true”).

The second shortcode skips the most recent post (offset=”1″) because we’re already showing it and then gives us the excerpt of the older posts (include_excerpt=”true”).

[[display-posts include_content="true" category="weeklyoverview" wrapper="div" image_size="large" posts_per_page="1"]]
<h2>Previous Weeks</h2>
[[display-posts include_excerpt="true" category="weeklyoverview" offset="1" wrapper="div"]]

That gets you something like this.
Screenshot of content showing one full post and excerpts of two other posts.


1 Now it’s in square brackets thanks to John’s comment! That had always irritated me and now it’s solved. Comments for the win.

5 thoughts on “Two Display Posts Tricks

  1. I have to agree. In the past I may have gotten more use from the Page-List plugin (for auto generating indexes based on page structure), but Display Posts has given me a lot too, saving from writing custom queries/loops (sometimes you have to for a grid layout that fits your theme). It Just Works.

    What’s really impressive are all the filters provided so you can extend it like you have done. And the developer writes a crazy volume of tutorials https://displayposts.com/tutorials/

    I’m looking at it for a project in my head to have the shortcode generate the posts but use jQuery called by second shortcode to manipulate it.

    1. I’ve got bits and pieces of a version that uses the JSON API to do similar stuff. The advantage is that you can grab content from other WP sites which can be strangely useful (at least in my world). It has made me appreciate just how complex creating that many options for a plugin can be. I’ll never get to that level but I am in a better position to admire it.

  2. I love display posts with a sprinkle of css. Great when your options are limited by lack of access or in my case knowledge. I use it a lot on Glow Blogs multisite where everything is locked tight.

    Fun tip you can show square brackets by wrapping the whole shortcode in another set of square brackets.

Comments are closed.