Posts are repeated in infinite scroll feature

Posted in: Newspaper
Post count: 21

I set the Block 3 component in home page as infinite scroll. Infinite scroll works but same posts are repeated in every new loading:

http://dl.dropbox.com/u/103580364/temp/000779.jpg

The web site is here:

http://test.hayatdefteri.com/

All plugins are deactivated.

Could you please check this problem? I send the access credentials to contact@tagdiv.com

Post count: 3343

reply to email

Post count: 21

Hi Marius,

The problem is caused by offset attribute in WP_Query as described here:

offset (int) – number of post to displace or pass over. Warning: Setting the offset parameter overrides/ignores the paged parameter and breaks pagination (Click here for a workaround).

A workaround is described here.

I try to implement that solution. Any help will be appreciated.

Post count: 780

Hello,

The pagination issue is some kind of incompatibility. In general the theme pagination should work well without any modifications.

Radu from tagDiv

Post count: 21

The pagination issue is caused by offset parameter. I set offset argument to 5 in order not to repeat the posts in the slider. But this causes the “paged” attribute in WP_Query to be ignored. This is documented in WP Codex:

offset (int) – number of post to displace or pass over.
Warning: Setting the offset parameter overrides/ignores the paged parameter and breaks pagination (Click here for a workaround).

Making Custom Queries Using Offset And Pagination
http://codex.wordpress.org/Making_Custom_Queries_using_Offset_and_Pagination

I adopted the solution above to my situation as here:

Newspaper-child\functions.php

add_action('pre_get_posts', 'myprefix_query_offset', 1 );
function myprefix_query_offset(&$query) {

    //Before anything else, make sure this is the right query...
    $not_in_ajax_call = get_permalink();
    $in_home_page = ! is_page('');
    if ( $not_in_ajax_call && $in_home_page ) {
        return;
    }
    if ( empty( $query->query['offset'] ) ) {
        return;
    }

    $offset = $query->query['offset'];

    //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. Just use the offset...
        $query->set('offset',$offset);
    }
}
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic.