Archived topic
Magazine Grid
16 replies · Started by JOAQUIM GALANTE on May 9, 2020
Hi David, do you remember this ?
'The magazine grid show the four recent posts and the frontpage repeat them. What happend, who see the site on mobile phone see on the first eight news four of them are repeated.
My question is, Is there a way to appear on the front page only after the fifth news?'
You send me the php codes and i introduce them on a snippets plugin and the things seems good in frontpage.....fantastic.
but on the second page only 4 news are different, 14 is the same of the page 1 and the same happens on the other pages.
Look, i have 18 news for page, when i change to page 2, 14 news are the same of the page 1, only 4 are new and so on in the others pages.
Have a solution for it ? Above the php insert on snippets plugin
function my_function_for_excluding_posts( $query ) {
if ($query->is_home() && $query->is_main_query()) {
$offset = 4;
$paged = 0 == $query->get( 'paged' ) ? 1 : $query->get( 'paged' );
$query->set( 'offset', $paged * $offset );
}
}
add_action( 'pre_get_posts', 'my_function_for_excluding_posts' );
function myprefix_adjust_offset_pagination($found_posts, $query) {
if ( $query->is_home() && $query->is_main_query() ) {
return $found_posts - 5;
}
return $found_posts;
}
add_filter('found_posts', 'myprefix_adjust_offset_pagination', 1, 2 );
I tried to change numbers (4, 0, 1, 5) but didn´t result.
Thanks
Hi there,
What if you do this instead?:
function my_function_for_excluding_posts( $query ) {
if ($query->is_home() && $query->is_main_query() && ! $query->is_paged()) {
$offset = 4;
$paged = 0 == $query->get( 'paged' ) ? 1 : $query->get( 'paged' );
$query->set( 'offset', $paged * $offset );
}
}
add_action( 'pre_get_posts', 'my_function_for_excluding_posts' );
function myprefix_adjust_offset_pagination($found_posts, $query) {
if ( $query->is_home() && $query->is_main_query() && ! $query->is_paged() ) {
return $found_posts - 5;
}
return $found_posts;
}
add_filter('found_posts', 'myprefix_adjust_offset_pagination', 1, 2 );
Let me know :)
Thanks Tom, this php has improved a lot compared to the previous one, almost perfect.
But there is a detail that needs to be improved to be perfect, from the 1st to the 2nd the last 4 motifs on page 1 appear at the top of page 2. But this only happens on page 2 on the others pages, everything is fine.
I left the plugin active to, if you want, can see what i am talking about on https://focusmsn.pt
Thanks a lot
Hmm, this is a complicated one.
What about this?:
function my_function_for_excluding_posts( $query ) {
if ($query->is_home() && $query->is_main_query()) {
$query->set( 'offset', 4 );
}
}
add_action( 'pre_get_posts', 'my_function_for_excluding_posts' );
function myprefix_adjust_offset_pagination($found_posts, $query) {
if ( $query->is_home() && $query->is_main_query() && ! $query->is_paged() ) {
return $found_posts - 4;
}
return $found_posts;
}
add_filter('found_posts', 'myprefix_adjust_offset_pagination', 1, 2 );
Hi Tom, it is the same. :(
What about now?: https://generatepress.com/forums/topic/magazine-grid-2/#post-1278117
With this one always repeat the page 1 in all pages, is worse.
If you see it is impossible to solve i give up.
Let's try to break down the logic a bit.
On the first page, we have the 4 featured posts at the top.
The next section should display the rest of the posts, minus those 4.
On the second/third etc.. pages, do you want those 4 featured posts to change? Shouldn't the featured posts only be on the first page? That way the query shouldn't need to change on the other pages.
What if the featured posts were tagged as "featured", and the regular posts excluded anything tagged as "featured"? That way you could just tag/untag as needed.
Hi Tom, you didn't understood the problem.
Forget the 4 featured posts ok.
On the first page i have 18 posts.
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 and 18 right ?
When i went in page 2 instead the first post was the 19 appear the 15,16,17,18,19 and só on.
Conclusion the 4 first post are the same of the page 1.
But that ONLY happens when i change the page 1 to page 2 in the next pages it is right.
If you go at https://focusmsn.pt you could see that.
Thanks.
And does that issue go away if you remove our custom functions above?
Yes, disappear. :)
If you see you can't solve this situation no problem, leave it.
I like the first page like that, even repeating 4 posts on the second page.
It shouldn't be repeating like that on the second page. Do you have any other functions added?
I think not, it is strange because only happens the page 1 for page 2.
Forget that, i think this is a challenge for you to improve the theme because have others do this for default.
Thanks a lot for the help. Hug
No problem - let me know if you ever want to re-visit it :)