Site logo

[Resolved] 9 blog items on home, 10 on following pages

Home Forums Support [Resolved] 9 blog items on home, 10 on following pages

Home Forums Support 9 blog items on home, 10 on following pages

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #2088520
    J.

    Hi there,

    I’m using the ‘Volume’ template. Is it possible to get 9 blog posts on the homepage and 10 on the following pages? It seems a bit odd when using the standard setup with the big featured post on the homepage.

    #2088566
    David
    Staff
    Customer Support

    Hi there,

    you would need to add this PHP Snippet to your site:

    add_action( 'pre_get_posts', 'sk_query_offset', 1 );
    function sk_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 = -1;
    
    	// 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', 'sk_adjust_offset_pagination', 1, 2 );
    function sk_adjust_offset_pagination( $found_posts, $query ) {
            if ( is_admin() ) {
                return;
            }
    
    	// Define our offset again...
    	$offset = -1;
    
    	// Ensure we're modifying the right query object...
    	if ( is_main_query() ) {
    		// Reduce WordPress's found_posts count by the offset...
    		return $found_posts - $offset;
    	}
    	return $found_posts;
    }
    
    

    This article explains how to add PHP:

    https://docs.generatepress.com/article/adding-php/

    #2088573
    J.

    I’ve pasted this in the functions.php from my (clean) child theme, but I see no results… Am I doing something wrong?

    #2088646
    David
    Staff
    Customer Support

    Can you share a link to the site ?

    #2089615
    J.

    Shared in the private info.

    #2090000
    Ying
    Staff
    Customer Support

    Hi Joe,

    The code should work, I just tested on my site.

    Can you disable all other plugins except GP premium and GB to test?

    #2422854
    jmarc

    Hi

    I use this code for my site but pagination is not working fine for the last page…
    Can you please take a look ?
    Thank you

    JMarc

    PS : how do I send you the URL in private so you can check the site ?

    #2423329
    jmarc

    Someone can help please ? Thank you 😉

    #2423331
    Leo
    Staff
    Customer Support

    Please open a new topic so you can use the private URL field:
    https://docs.generatepress.com/article/using-the-premium-support-forum/#open-support-topic
    https://docs.generatepress.com/article/using-the-premium-support-forum/#private-information

    Please also be mindful that it’s Saturday here so our responses will be slower:
    https://generatepress.com/what-support-includes/

    Thanks for your understanding 🙂

    #2423342
    jmarc

    I’ll do that and I thank you Leo ….

    #2424464
    Leo
    Staff
    Customer Support

    Thanks 🙂

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