Infinite scroll and first page duplicate posts
-
OK i’ve been doing all the rounds on this one and still can’t find a solution!
I have a site which the client wants to use infinite scroll across custom post types. I can get this to work for for some reason after the first 10 posts are loaded in, the next 10 posts are the first 10, and then the page continues to load in as it should.
Am running Masonry with this too.
Anyone have any ideas which it’s doing this? Thought it be to do with having first 10 posts display on the posts page, but not sure now.
Have got this in my function file:
// Jetpack Infinite scroll
function enqueue_masonry_script() {
wp_enqueue_script(‘masonry-script’, get_template_directory_uri() . ‘/js/masonry.pkgd.min.js’, array(‘jquery’));
}
add_action(‘wp_enqueue_scripts’, ‘enqueue_masonry_script’);function my_load_infinite_scroll( $load_infinite_scroll ) {
if( is_post_type_archive(‘gallery’) )
return true;
return $load_infinite_scroll;
}
add_filter(‘infinite_scroll_load_override’, ‘my_load_infinite_scroll’);add_theme_support( ‘infinite-scroll’, array(
‘container’ => ‘pageRowMasonry’,
‘wrapper’ => false,
‘render’ => false,
‘footer’ => false,
‘posts_per_page’ => ‘7’
) );This is the jQuery which loads in the footer:
<script>
// 1 Masonry first state
jQuery(‘.js-masonry’).imagesLoaded( function(){
jQuery(‘.js-masonry’).masonry({
isAnimated: true,
isFitWidth: true,
“gutter”: 20,
transitionDuration: 0
});
});// 2 Masonry second state
jQuery( document ).ready( function( $ ) {
infinite_count = 0;
// Triggers re-layout on infinite scroll
$(document.body).on(‘post-load’, function() {
infinite_count = infinite_count + 1;
var $container = $(‘#pageRowMasonry’);
var $selector = $(‘#infinite-view-‘ + infinite_count);
var $elements = $selector.find(‘.pagePhotoshootsContainer’);
$elements.hide();
$container.masonry(‘reloadItems’);
$elements.fadeIn();jQuery(‘.js-masonry’).masonry({
isAnimated: true,
isFitWidth: true,
“gutter”: 20,
transitionDuration: 0
});});
});
</script>Then calling in the posts:
$args = array(‘posts_per_page’ => 10, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’);
query_posts($args);
if ( have_posts() ) :…..I have also tried using an array in a session to match post>id, but to no avail.
- The topic ‘Infinite scroll and first page duplicate posts’ is closed to new replies.