Often people, that use WordPress to power their website and blog, require posts from a certain category to show on a page along with the content of the page itself. We build many websites using the StudioPress Genesis framework and fortunately it’s easy to add a categories posts to a page whilst keeping the test, video, images or other content displayed.
How to show content on a blog page
To display the page content before the posts we need to make a once-off change. Here are the instructions:
- Create a file called page_blog.php.
- Save the following to the new file
<?php //* Template Name: Blog //* Show page content above posts add_action( 'genesis_loop', 'genesis_standard_loop', 5 ); genesis();
- Using FTP, copy the file that we’ve created to your StudioPress child theme on your webserver.
Any content you’ve included on the Page that you’ve assigned to the Blog template will now display before the list of posts.
How to show posts from a single category on a page
To show only some categories on each blog page, we merely need go to Blog Page Template settings in Genesis theme settings (categories included or excluded from the blog template are set here). But what if we want to show multiple pages with blog posts and each page needs to show a different category. Luckily this is also very simple.
Here is how to show posts from a single category on a blog page in the Genesis framework:
- Create your page and assign the Blog template.
- Add any content you want on the page (assuming you’ve followed the tutorial above, your content will show above your posts).
- Find the category ID of the category which you want displayed (i.e. go to Dashboard -> Posts -> Categories and click on your selected category. The URL of the category will contain the category ID e.g. look for category&tag_ID=1404&post_type=post; the 1404 is the Category ID).
- In the edit screen of the page go to the Custom Fields section and add the following; In NAME enter query_args. In Value enter cat=1404 (change the number for your category ID).
- Click Add Custom Field and save your page changes.
Only posts from your selected category will now show on this page. If you want to see a working example the take a look at our Mailchimp experts page where you’ll notice Mailchimp categorized posts under the page content.