Blog's page 2 is a duplicate of page 1 (Minimum 2.0)

Community Forums Forums General Discussion Blog's page 2 is a duplicate of page 1 (Minimum 2.0)

This topic is: resolved

This topic contains 2 replies, has 1 voice, and was last updated by  BengtSather 1 year, 8 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #36103

    BengtSather
    Participant
    Post count: 5

    Hi there

    My name is Bengt Sather. I’ve tried to find a solution to my problem here on the forum without luck.

    This is my site: Tektor.no

    I’m using Minimum 2.0.

    My problem is this:

    I’m using a blog page as the front page (static page). I have a total of 11 posts so far. I’ve set WordPress to display 10 posts on the first page. But when I click on “Neste side (next page)”, page 2 is still showing my 10 latest posts and not the 11th. Page 2 is a duplicate of page 1.

    How can I fix this?

    Still smiling :)

    Bengt

    http://www.tektor.no/
    #36104

    BengtSather
    Participant
    Post count: 5

    I should probably add that I’m using a grid loop code from Bill Erickson that I found here: http://www.billerickson.net/a-better-and-easier-grid-loop/

    This is my version:

    /**
    * Grid Loop Pagination
    * Returns false if not grid loop.
    * Returns an array describing pagination if is grid loop
    *
    * @author Bill Erickson
    * @link http://www.billerickson.net/a-better-and-easier-grid-loop/
    *
    * @param object $query
    * @return bool is grid loop (true) or not (false)
    */
    function be_grid_loop_pagination( $query = true ) {

    // If no query is specified, grab the main query
    global $wp_query;
    if( !isset( $query ) || empty( $query ) || !is_object( $query ) )
    $query = $wp_query;

    // Sections of site that should use grid loop
    if( ! ( $query->is_home() || $query->is_archive() ) )
    return false;

    // Specify pagination
    return array(
    'features_on_front' => 0,
    'teasers_on_front' => 10,
    'features_inside' => 0,
    'teasers_inside' => 10,
    );
    }

    /**
    * Grid Loop Query Arguments
    *
    * @author Bill Erickson
    * @link http://www.billerickson.net/a-better-and-easier-grid-loop/
    *
    * @param object $query
    * @return null
    */
    function be_grid_loop_query_args( $query ) {
    $grid_args = be_grid_loop_pagination( $query );
    if( $query->is_main_query() && !is_admin() && $grid_args ) {


    // First Page
    $page = $query->query_vars['paged'];
    if( ! $page ) {
    $query->set( 'posts_per_page', ( $grid_args['features_on_front'] + $grid_args['teasers_on_front'] ) );


    // Other Pages
    } else {
    $query->set( 'posts_per_page', ( $grid_args['features_inside'] + $grid_args['teasers_inside'] ) );
    $query->set( 'offset', ( $grid_args['features_on_front'] + $grid_args['teasers_on_front'] ) + ( $grid_args['features_inside'] + $grid_args['teasers_inside'] ) * ( $page - 2 ) );
    // Offset is posts on first page + posts on internal pages * ( current page - 2 )
    }


    }
    }
    add_action( 'pre_get_posts', 'be_grid_loop_query_args' );


    /**
    * Grid Loop Post Classes
    *
    * @author Bill Erickson
    * @link http://www.billerickson.net/a-better-and-easier-grid-loop/
    *
    * @param array $classes
    * @return array $classes
    */
    function be_grid_loop_post_classes( $classes ) {
    global $wp_query;
    $grid_args = be_grid_loop_pagination();
    if( ! $grid_args )
    return $classes;


    // First Page Classes
    if( ! $wp_query->query_vars['paged'] ) {


    // Features
    if( $wp_query->current_post < $grid_args['features_on_front'] ) { $classes[] = 'feature'; // Teasers } else { $classes[] = 'one-half'; if( 0 == ( $wp_query->current_post - $grid_args['features_on_front'] ) || 0 == ( $wp_query->current_post - $grid_args['features_on_front'] ) % 2 )
    $classes[] = 'first';
    }


    // Inner Pages
    } else {


    // Features
    if( $wp_query->current_post < $grid_args['features_inside'] ) { $classes[] = 'feature'; // Teasers } else { $classes[] = 'one-half'; if( 0 == ( $wp_query->current_post - $grid_args['features_inside'] ) || 0 == ( $wp_query->current_post - $grid_args['features_inside'] ) % 2 )
    $classes[] = 'first';
    }


    }


    return $classes;
    }
    add_filter( 'post_class', 'be_grid_loop_post_classes' );


    /**
    * Grid Image Sizes
    *
    */
    function be_grid_image_sizes() {
    add_image_size( 'be_grid', 353, 200, true );
    add_image_size( 'be_feature', 570, 333, true );
    }
    add_action( 'genesis_setup', 'be_grid_image_sizes', 20 );


    /**
    * Grid Loop Featured Image
    *
    * @param string image size
    * @return string
    */
    function be_grid_loop_image( $image_size ) {
    global $wp_query;
    $grid_args = be_grid_loop_pagination();
    if( ! $grid_args )
    return $image_size;


    // Feature
    if( ( ! $wp_query->query_vars['paged'] && $wp_query->current_post < $grid_args['features_on_front'] ) || ( $wp_query->query_vars['paged'] && $wp_query->current_post < $grid_args['features_inside'] ) ) $image_size = 'be_feature'; if( ( ! $wp_query->query_vars['paged'] && $wp_query->current_post > ( $grid_args['features_on_front'] - 1 ) ) || ( $wp_query->query_vars['paged'] && $wp_query->current_post > ( $grid_args['features_inside'] - 1 ) ) )
    $image_size = 'be_grid';


    return $image_size;
    }
    add_filter( 'genesis_pre_get_option_image_size', 'be_grid_loop_image' );


    /**
    * Fix Posts Nav
    *
    * The posts navigation uses the current posts-per-page to
    * calculate how many pages there are. If your homepage
    * displays a different number than inner pages, there
    * will be more pages listed on the homepage. This fixes it.
    *
    */
    function be_fix_posts_nav() {


    if( get_query_var( 'paged' ) )
    return;


    global $wp_query;
    $grid_args = be_grid_loop_pagination();
    if( ! $grid_args )
    return;


    $max = ceil ( ( $wp_query->found_posts - $grid_args['features_on_front'] - $grid_args['teasers_on_front'] ) / ( $grid_args['features_inside'] + $grid_args['teasers_inside'] ) ) + 1;
    $wp_query->max_num_pages = $max;


    }

    #36105

    BengtSather
    Participant
    Post count: 5

    Sorry – I messed up when I tried to insert the code. I will try to fix it asap.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.