Published on Jun 2, 2021

Posts Grouped by Categories in WordPress

Sridhar Katakam

This members-only tutorial provides the steps to automatically display posts in WordPress grouped by their categories.

We shall get all the non-empty categories in ascending order, loop through them, show the category title with the category archive link and for each, fetch three latest posts from that category, print the featured image + post title linked to the permalink for each post and style the output using CSS Grid.

While the steps are Oxygen-specific, this works in any WordPress site.

Step 1 - Register Custom Image Size

Register a custom image size for the featured images in the posts.

Add the following Code Snippet:

add_image_size( 'category_image', 600, 338, true ); // 16 x 9

Regenerate thumbnails.

Step 2 - The PHP

Create a static Page and edit it with Oxygen.

Add a Code Block.

Set its width to 100%.

PHP & HTML:

This is a premium members-only content.

To view the rest of the content, please sign up for membership ($47/month or $499 one-time).

Already a member? Log in below or here.

tagschevron-leftchevron-rightchainangle-rightangle-upangle-downfolder-omagnifiercrossmenuchevron-downarrow-right