The Post Grid styling works great if you know how many posts will be returned, but it doesn’t look good to have a single post in a 3 column grid. The code below will add an additional class to the wrapper indicating the number of posts in the result (ex: count-4). You can then adjust […]
Author: Bill Erickson
Bill Erickson is a freelance WordPress developer and a contributor to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.
List posts that match ALL categories or tags
Display Posts includes many query parameters for determining which posts are shown. If you use the category or category_id parameters and include multiple categories, it will find posts that have any of those categories. If you would like to list only posts that have all of those categories, you can use the taxonomy query parameters. […]
Display random posts
By default Display Posts will show your posts ordered by publish date, with the newest first. You can use the orderby parameter to change this to any other ordering method. To list random posts, use: You can use the other query parameters along with this to pick from a smaller selection. For instance, if you […]
Pagination in Display Posts
Unfortunately this plugin does not support pagination. You can use the posts_per_page parameter to decide how many posts to display on the current page, Display Posts will not add previous/next links below this list to explore further. I’m planning to build a Pagination Extension in the near future, once I’ve finished building the Gutenberg block […]
List related posts with the same tag
You can use the shortcode to list recent posts with “my-tag”. But what if you’d like to show other posts in the current post’s tag without having to type it out each time. This is especially useful in widgets and sidebars since you can add the shortcode once and it will automatically update to show […]
Include comment count and link to comments
Display Posts includes many Display Parameters for customizing what is shown for each post in the list. It does not include an option for listing the comment count, but you can add one yourself using the Output Filter. Once the code below has been added to your site, you can include the comments link like […]
Open links in a new window
The links in Display Posts all open in the current window. We can use the output filter to modify this, making all links open in a new window:
Caching queries to improve performance
This is available as a separate plugin: Display Posts – Transient Cache Some users will build very complex queries involving multiple taxonomy and meta queries. These can be computationally expensive to run, and running the query on every uncached pageload is not necessary. We can store the output of the shortcode in a transient – […]
Exclude category
There are a few ways you can exclude posts in certain categories from your listings. By Category ID By default, the category_id parameter limits results to posts IN these categories. For instance, displays posts in the category with an ID of 123. You can use negative numbers to exclude categories. If you want posts in […]
Display inline link with most recent post
Display Posts includes a few different options for wrappers (unordered list, ordered list, and div) but all of these are block-level elements. That means they display as their own unique block on the page. If you want to display the most recent post inside a paragraph, we’ll need to use an inline element. The code snippet […]