Site logo

Archived topic

Category Archive pages - Adding a query loop before category post list

7 replies · Started by Paul on February 25, 2023

Viewing posts 1–8 of 8

Hi There,

Could you help me with the following.

I'd like to add a I'd 3 'featured' posts before the archive of all posts in category archive page. Could you give me any pointers on how I could do that (example page in private info)?

cheers

Hi there,

the featured posts .. are they specific to each category ?

Hi David,

Yes they would featured posts from the same category so ideally would like to filter those out posts from the full listings for the archive below, if that makes sense.

So would be:

CATS CATEGORY

Cats Featured Post 1 | Cats Featured Post 2 | Cats Featured Post 3
____________________________________________________________________________________

List of other Posts in Category (filtered to not display 3 featured posts above)

Hi Paul,

Yes, you can use a block element - loop template, and assign it to the category archive.

You will be adding 2 GB query loop blocks.

The 1st query loop block is to have 3 featured posts, you can manually select the 3 posts.
The 2nd query loop block is to have the rest posts, you can exclude the 3 posts.

Great, thank you Ying - I'll try that.

No problem :)

Hi Ying,

I gave that a try (I only added the first query loop block so far) - See link in private info.

Although I ran into an issue - what if we want the 'Featured posts' query loop block container to only show on the first page of the category archive (currently shows on all pages)?

Cheers

Add this snippet to your site:

function db_hide_block_on_paged( $block_content, $block ) {
    if ( is_paged() && ! empty( $block['attrs']['className'] ) && 'hide-on-paged' === $block['attrs']['className'] ) {
        $block_content = '';
    } 
    return $block_content;
}
 
add_filter( 'render_block', 'db_hide_block_on_paged', 10, 2 );

Then any Block you want to remove on paged instances eg. the parent Container holding your featured post loop, give it an Advanced > Additional CSS Class of: hide-on-paged

This archived topic is closed to new replies.