- This topic has 9 replies, 2 voices, and was last updated 3 years, 4 months ago by
Ying.
-
AuthorPosts
-
December 22, 2022 at 11:28 am #2470840
jmarc
Hello
everything is in the title. I can’t find a way to do that. Can you please help ?
Thank you
MArcDecember 22, 2022 at 12:55 pm #2470904Ying
StaffCustomer SupportHi there,
Can you link us to the homepage and the other pages you are referring to?
December 22, 2022 at 12:59 pm #2470907jmarc
Hello Ying
Yes ! In private message you can get the URL
Thank youMArc
December 22, 2022 at 1:38 pm #2470934Ying
StaffCustomer Support1. Go to settings > reading, and set the
Blog pages show at mostto16.2. Add this PHP snippet:
add_action( 'pre_get_posts', 'yh_query_offset', 1 ); function yh_query_offset( &$query ) { if ( is_admin() ) { return; } // Before anything else, make sure this is the right query... if ( ! ( is_main_query() ) ) { return; } // Don't do anything to Elements. if ( 'gp_elements' === $query->get( 'post_type' ) ) { return; } // First, define your desired offset... $offset = -4; // Next, determine how many posts per page you want (we'll use WordPress's settings) $ppp = get_option( 'posts_per_page' ); // Next, detect and handle pagination... if ( $query->is_paged ) { // Manually determine page query offset (offset + current page (minus one) x posts per page) $page_offset = $offset + ( ( $query->query_vars['paged']-1 ) * $ppp ); // Apply adjust page offset $query->set( 'offset', $page_offset ); } else { // This is the first page. Set a different number for posts per page $query->set( 'posts_per_page', $offset + $ppp ); } } add_filter( 'found_posts', 'yh_adjust_offset_pagination', 1, 2 ); function yh_adjust_offset_pagination( $found_posts, $query ) { if ( is_admin() ) { return; } // Define our offset again... $offset = -4; //get posts per page from WP settings $ppp = get_option( 'posts_per_page' ); $real_page_numbers =ceil(($found_posts - $ppp - $offset) / $ppp) + 1; // Ensure we're modifying the right query object... if ( is_main_query() && ! is_paged() ) { // Reduce WordPress's found_posts count by the offset... return $real_page_numbers * ($ppp + $offset); } return $real_page_numbers * $ppp; }Adding PHP: https://docs.generatepress.com/article/adding-php/
December 22, 2022 at 1:42 pm #2470937jmarc
Thank you but It also shows 16 in the right sidebar “Last post” … and random image 🙁
December 22, 2022 at 1:48 pm #2470944Ying
StaffCustomer SupportThe query in the sidebar is the same as the main query of the blog, these are repeated content which I don’t think is good for SEO.
Will you consider removing them from the blog?
December 22, 2022 at 1:52 pm #2470948jmarc
Noop, the plugin is “Recent Posts Widget With Thumbnails” and I want to keep it, I think It looks good on the website
If my demande is not possible : never mind … or maybe you have another solution to fix this ?Thank you for your kind help anyway
MArcDecember 22, 2022 at 2:04 pm #2470956Ying
StaffCustomer SupportIn that case, I would recommend reaching out to the plugin support and asking how to target their loop.
Show them the PHP snippet, they should be able to help!
December 22, 2022 at 2:06 pm #2470960jmarc
I’ll do that thank’s a lot
MarcDecember 23, 2022 at 12:16 pm #2471855Ying
StaffCustomer SupportNo Problem, glad to help 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.