Site logo

Archived topic

Featured post showing on other pages

1 reply · Started by Brian on August 1, 2022

Viewing posts 1–2 of 2

I created a new homepage layout using query loops. I created a new page https://sluggerotoole.com/home and set home to homepage in settings.

It all works, the only issue is when you go to pagination at the bottom and click on page 2 the featured post shows on the next.

Any idea how to stop it showing?

Should I have set the featured post as a hero section element instead?

Thanks

Hi there,

we're looking at how to add conditional display rules for blocks, so you can remove them if the template viewed is_paged for example.

Its not easy and the best i can offer today is a PHP Snippet to remove it if the you use the pagination.

1. Add this PHP Snippet:

function db_hide_block_on_paged( $block_content, $block ) {
    if ( strpos($_SERVER['REQUEST_URI'], "-page=") && ! 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 );

2. Select the Container Block with your Featured Post, and in Advanced > Additional CSS Class(es) add: hide-on-paged

The only issue is, if you use the pagination and go back to Page 1 using pagination then it still treats it as pagination. So the featured post will be missing.

This archived topic is closed to new replies.