In home page it loads the more post correctly. But when i use the same code for loading more post in single.php
(i.e article page), it not loading correctly. on the intial load it shows 3 post as per the given query.
if i click on load more post button it again loads the same post which already loaded. How to solve this?
Here is the java script code:
<script type="text/javascript">
jQuery(document).ready(function($) {
<?php $mvp_infinite_scroll = get_option('mvp_infinite_scroll'); if ($mvp_infinite_scroll == "true") { if (isset($mvp_infinite_scroll)) { ?>
// Infinite Scroll
$('.infinite-content').infinitescroll({
navSelector: ".nav-links",
nextSelector: ".nav-links a:first",
itemSelector: ".infinite-post",
loading: {
msgText: "<?php esc_html_e( 'Loading more posts...', 'mvp-text' ); ?>",
finishedMsg: "<?php esc_html_e( 'Sorry, no more posts', 'mvp-text' ); ?>"
}
});
$(window).unbind('.infscr');
$(".inf-more-but").click(function(){
$('.infinite-content').infinitescroll('retrieve');
return false;
});
<?php } } ?>
});
</script>
Here is the PHP and HTML code :
<div id="archive-list-wrap" class="left relative">
<?php if(get_option('mvp_arch_layout') == 'Column' ) { ?>
<ul class="archive-col-list left relative infinite-content">
<?php } else { ?>
<ul class="archive-list left relative infinite-content">
<?php } ?>
<?php
$category = get_the_category($post->ID);
$name = $category[0]->cat_name; ?>
<?php global $do_not_duplicate; $mvp_posts_num = esc_html(get_option('mvp_posts_num')); $paged = (get_query_var('page')) ? get_query_var('page') : 1; query_posts(array( 'order' => 'DESC', 'orderby' => 'date', 'post__not_in' => array($post->ID),'posts_per_page' => $mvp_posts_num ,'category_name' => $name, 'ignore_sticky_posts'=> 1,'paged' =>$paged ));while (have_posts()) : the_post();$do_not_duplicate[] = $post->ID; ?>
<?php //global $do_not_duplicate; global $post; $recent = new WP_Query(array( 'tag' => get_option('mvp_feat_posts_tags'), 'posts_per_page' => $mvp_posts_num )); while($recent->have_posts()) : $recent->the_post(); $do_not_duplicate[] = $post->ID; if (isset($do_not_duplicate)) { ?>
<li class="infinite-post">
<div class="archive-list-out">
<div class="archive-list-img left relative infinite-content">
<?php if ( (function_exists('has_post_thumbnail')) && (has_post_thumbnail()) ) { ?>
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>">
<?php the_post_thumbnail('mvp-mid-thumb', array( 'class' => 'reg-img' )); ?>
<?php the_post_thumbnail('mvp-small-thumb', array( 'class' => 'mob-img' )); ?>
</a>
<?php } ?>
<?php if ( has_post_format( 'video' )) { ?>
<div class="feat-vid-but">
<i class="fa fa-play fa-3"></i>
</div><!--feat-vid-but-->
<?php } ?>
</div><!--related-img-->
</div><!--related-img-->
<div class="archive-list-in">
<div class="archive-list-text left relative">
<!--post date-->
<div class="posted-date">
<span class="post-date"><time class="post-date updated" itemprop="datePublished" datetime="<?php the_time('Y-m-d'); ?>"><?php the_time(get_option('date_format')); ?></time></span>
</div>
<a class="post-cat-link" href="<?php $category = get_the_category(); $category_id = get_cat_ID( $category[0]->cat_name ); $category_link = get_category_link( $category_id ); echo esc_url( $category_link ); ?>"><span class="post-head-cat"><?php $category = get_the_category(); echo esc_html( $category[0]->cat_name ); ?></span></a>
<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
</div><!--related-text-->
</div><!--related-text-->
</li>
<?php endwhile; wp_reset_postdata();?>
</ul>
<?php $mvp_infinite_scroll = get_option('mvp_infinite_scroll'); if ($mvp_infinite_scroll == "true") { if (isset($mvp_infinite_scroll)) { ?>
<?phpif($mvp_posts_num == 3){?>
<a href="#" class="inf-more-but"><?php _e( 'More Posts', 'mvp-text' ); ?></a>
<?php}?>
<?php } } ?>
<div class="nav-links">
<?php if (function_exists("pagination")) { pagination($wp_query->max_num_pages); } ?>
</div>
</div>