One of the primary reasons why people love using WordPress is because of its capacity for customization. Everything from themes to the plugins you use can give the site a completely different appearance. What if you want to easily show category posts in your content?
While showing posts can be done through custom page building, sometimes an easier solution is more ideal. Luckily, you can list posts from categories in your content without committing to extensive alterations or creating elaborate pages.
Today, I’m going to show you how to use a shortcode to easily list posts from categories within your content. Not only is this a time-saving practice, but it can also give you greater control over customizing the appearance of your website.
What are shortcodes?
In a nutshell, shortcodes are snippets of coding WordPress uses to perform certain functions. These use a bracket system to separate the function from the rest of your content.
Because you can use these snippets of coding anywhere in a post or page, they are quite versatile when customizing an appearance. Some will offer tools while others may simply list other content on your website.
While WordPress has a few of these shortcodes already in its system, there are a number of plugins that add even more to the list of what you can do. In fact, a large number of styling or layout plugins for the homepage will come with shortcodes of their own.
Listing Category Posts with a Shortcode in WordPress
For this tutorial, I will be using the List category posts plugin. This particular tool has a long list of parameters that can be set to create the perfect appearance for your task. If you use this plugin, I suggest reading the documentation to learn all the features it has available. The functionality of the plugin is quite extensive, and you may find even more uses by reading up on the tool.
The listing of the posts will look like links in a bullet list by default. You can customize the overall appearance of the list by using the additional supported commands that come with the plugin. Again, I urge you to read the functions that are available. It will drastically change how you look at the tool.
To use this plugin to display your category posts:
Step 1: Go to the plugins area of your WordPress admin dashboard.
Step 2: Add a new plugin and search for, “List category posts.”
NOTE: You will see a lot of plugins that are titled similar. You want the plugin developed by Fernando Briano.
Step 3: Install and activate the plugin. This will add a new function to the settings area of WordPress.
Step 4: Go to “Settings” and click on the link for this plugin.
Step 5: In the settings page, choose the number of posts you want to display by default. Currently, this is set to 10. Let’s change this to “8.” This will tell WordPress to show eight posts for the category.
NOTE: When you add the “numberposts” to the shortcode, it will override this setting. For instance, “[catlist numberposts=6]” will only show six posts in the category regardless of what the settings page is set to.
Step 6: For now, leave the rest of the settings as they are and click “Save Changes” at the bottom.
Step 7: Create a new post in WordPress.
Step 8: In the editor, place the following code at the bottom of your text:
Step 9: Save the draft of your post and click the “View Post” in the top admin bar. This will open the draft in a new tab.
Step 10: By default, WordPress will use the most recent posts when using the shortcode. As you can see, it will list the titles of the pieces themselves. What if you want them for a specific category? Go back to your post and I’ll show you how to do this. Close the draft tab.
Step 11: Change the shortcode by adding the name of the category you wish to display. When assigning the name of the category in the shortcode, use the “slug” for easy use. For instance, it would read something like:
NOTE: The slug is found by going to the categories section of WordPress and clicking any one of the titles in this section.
Step 12: Save the draft and view the post again. Now, you should see eight of the most recent posts from that particular category. Close the draft tab and go back to WordPress.
Step 13: What if you want to use more than one category? That is done by adding a “+” in between each category name, for instance:
Step 14: Save the file and go to the appearance area in the left admin panel of WordPress.
Step 15: Click into the widgets section.
Step 16: Look for the category posts plugin’s widget and drag it to your sidebar.
Step 17: You’ll see a variety of options available to display your categories. You can modify things such as the category being displayed in the widget, number posts, post attributes and other modifications. Once you make your selections, click the “Save” button on the bottom right.
This is only a handful of things you can do with the plugin. It can show posts according to dates, authors, tags and even include excerpts. By adding “thumbnail” to the shortcode, you can also include the posts featured image. These functions are all detailed in the documentation I mentioned earlier.
Ideas for how to use shortcodes to shows posts
The plugin I used for this tutorial is full of all kinds of customizing options. From basic content links to more elaborate functions, you can set up a page for specific types of content to make browsing easier for visitors. Here are just a few ideas that may help you get started.
Creating Internal Links
Using this shortcode to display additional content helps the site by creating internal links. Visitors are able to find more content easier that is relevant to the current topic. This is especially useful if you display posts according to tags and specific categories. Because the code will pull the most recent pieces by default, these links will always be up-to-date.
Showing Author Pride
Perhaps you have an area of your site dedicated to specific authors. This shortcode allows you to show the individual’s most current pieces in the event there are visitors who are fans of that writer. You can even add the author’s personal URL if there is one saved in WordPress.
Faster Way to Show Content
If you set up the shortcode with your specific settings, such as using numberposts or thumbnail=yes, these can get quite long. Instead of typing them out every time, why not save them as a template in a Notepad file or use the TinyMCE Templates plugin to save them? That way, you can quickly paste those elaborate shortcodes without trying to remember how each one is set up.
Shortcodes are an invaluable part of customizing a WordPress website. Not only are they easy to use, but they have a great deal of versatility. Whether you’re showing posts from a related tag or displaying content developed during a certain month, a lot can be done with this plugin. Explore the potential of what you can do and boost the capabilities of your WordPress site.
How often do you use shortcodes to add functionality to a post or page? What kind of shortcodes do you use in your projects?
Author: Josh Dargie
My name is Josh Dargie and I’m the Operations Manager at GreenGeeks. I’ve been with the company since 2009. I have over 16 years of experience working with and for various web hosting providers specifically in development, day-to-day operations and customer service.