Site logo

[Support request] I would like to get 12 post on the homepage and 16 on the other pages

Home Forums Support [Support request] I would like to get 12 post on the homepage and 16 on the other pages

Home Forums Support I would like to get 12 post on the homepage and 16 on the other pages

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #2470840
    jmarc

    Hello
    everything is in the title. I can’t find a way to do that. Can you please help ?
    Thank you
    MArc

    #2470904
    Ying
    Staff
    Customer Support

    Hi there,

    Can you link us to the homepage and the other pages you are referring to?

    #2470907
    jmarc

    Hello Ying

    Yes ! In private message you can get the URL
    Thank you

    MArc

    #2470934
    Ying
    Staff
    Customer Support

    1. Go to settings > reading, and set the Blog pages show at most to 16.

    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/

    #2470937
    jmarc

    Thank you but It also shows 16 in the right sidebar “Last post” … and random image 🙁

    #2470944
    Ying
    Staff
    Customer Support

    The 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?

    #2470948
    jmarc

    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
    MArc

    #2470956
    Ying
    Staff
    Customer Support

    In 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!

    #2470960
    jmarc

    I’ll do that thank’s a lot
    Marc

    #2471855
    Ying
    Staff
    Customer Support

    No Problem, glad to help 🙂

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.