- This topic has 16 replies, 2 voices, and was last updated 4 years, 9 months ago by
JOAQUIM GALANTE.
-
AuthorPosts
-
May 9, 2020 at 12:22 pm #1277145
JOAQUIM GALANTE
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
May 9, 2020 at 5:05 pm #1277319Tom
Lead DeveloperLead DeveloperHi 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 🙂
May 10, 2020 at 3:06 am #1277580JOAQUIM GALANTE
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
May 10, 2020 at 10:27 am #1278117Tom
Lead DeveloperLead DeveloperHmm, 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 );May 10, 2020 at 10:35 am #1278121JOAQUIM GALANTE
Hi Tom, it is the same. 🙁
May 10, 2020 at 10:38 am #1278122Tom
Lead DeveloperLead DeveloperWhat about now?: https://generatepress.com/forums/topic/magazine-grid-2/#post-1278117
May 10, 2020 at 10:46 am #1278140JOAQUIM GALANTE
With this one always repeat the page 1 in all pages, is worse.
If you see it is impossible to solve i give up.
May 10, 2020 at 3:47 pm #1278331Tom
Lead DeveloperLead DeveloperLet’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.
May 10, 2020 at 4:23 pm #1278360JOAQUIM GALANTE
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.
May 11, 2020 at 9:04 am #1279399Tom
Lead DeveloperLead DeveloperAnd does that issue go away if you remove our custom functions above?
May 11, 2020 at 9:05 am #1279403JOAQUIM GALANTE
Yes, disappear. 🙂
May 11, 2020 at 9:11 am #1279411JOAQUIM GALANTE
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.
May 11, 2020 at 5:29 pm #1279990Tom
Lead DeveloperLead DeveloperIt shouldn’t be repeating like that on the second page. Do you have any other functions added?
May 12, 2020 at 1:12 am #1280357JOAQUIM GALANTE
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
May 12, 2020 at 10:19 am #1281219Tom
Lead DeveloperLead DeveloperNo problem – let me know if you ever want to re-visit it 🙂
-
AuthorPosts
- The topic ‘Magazine Grid’ is closed to new replies.