WordPress: Displaying posts of a particular category on a custom page

Displaying posts of a particular category on a custom page in WordPress

Displaying posts of a particular category on a custom page in WordPress

Today, I wanted to render all posts belonging to a category on a custom page. It's unfortunate that WordPress doesn't provide an easy way to achieve this. I tried WP Posts Filter plugin, but it didn’t seem to work its magic. But the following method worked for me.

Before you proceed, you will need to keep your Page slug (last part of url e.g. www.domain.com/slug) and your Category slug handy, both of which can be found in Pages and Categories options in the left menu bar of WordPress Administrator area.

Now, the main bit:

Navigate to wp-content > themes > your_theme_name

edit page.php as follows

place cursor before the opening php tag (<?php) in the while loop line.

That’s it! Googling ‘query_posts wordpress’ will give you an idea of what all parameters can be passed in the array function.

EDIT: The above method lists all posts of a category on a single page, without pagination. To introduce layout similar to what we get when we click on a category, I ended up discarding the above method, and switched to a plugin named 'Category Redirection for WordPress', available in the wordpress plugin store by the name of 'Redirection' by John Godley. It is very easy to implement, as can be seen here. To reiterate the steps:

Go to the Plugin Store by: Go to your WordPress admin area > Hover over Plugins option in the menu > Click on Add New.

Look for 'Redirection' by John Godley in the store. Install the plugin.

Once installed, in the admin area menu, hover over Tools, and click on Redirection.

Look for the form under the heading 'Add new redirection'. Fill the form as follows:

Source URL: /your-category-name/ (You can enter the absolute path to the category here as well, such as www.site.com/your-category-name/. However, it is advised that you enter the relative path.)

Match: URL Only

Action: Redirect to URL

Regular Expression: Unchecked

Target URL: /your-page-slug/ (You can enter the absolute path to the target url here as well, such as www.site.com/your-page-name/. However, it is advised that you enter the relative path.)

Click on Add Redirection button. You are good to go!

There you go, now you can view all posts within a category on a custom page, using the Redirection plugin by John Godley.