Site logo

Archived topic

hide post display already magazine grid on the blog page

3 replies · Started by SEBASTIEN on January 24, 2021

Viewing posts 1–4 of 4

hello, I am very happy to use generate press for my projects, I have a question especially concerning the theme dispatch with the magazine grid.

I use this little function to remove the posts already published on my home page, keeping the main article in the grid magazine, but this does not work on my blog category page, can you direct me ?

//hide posts which have been displayed already
add_filter('post_link', 'track_displayed_posts');
add_action('pre_get_posts','remove_already_displayed_posts');

$displayed_posts = [];

function track_displayed_posts($url) {
global $displayed_posts;
$displayed_posts[] = get_the_ID();
return $url; // don't mess with the url
}

function remove_already_displayed_posts($query) {
global $displayed_posts;
$query->set('post__not_in', $displayed_posts);
}

Hi there,

can you share a link to a Category page where i can see the issue?

it's resolved, I needed to do set( 'offset', '4' ); for is_archive.

but maybe there is a better solution?

see ya

Seb

Thats a valid solution. The only issue you may have is if it is used on a paginated archive, as WP doesn't handle offset very well in that instance.

This archived topic is closed to new replies.