在主页中,它会正确加载更多帖子。但是当我使用相同的代码加载更多的帖子时single.php
(即文章页),未正确加载。在初始加载时,根据给定的查询显示3个post。如果我单击“加载更多帖子”按钮,它会再次加载已加载的帖子。如何解决这个问题?
以下是java脚本代码:
<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>
以下是PHP和HTML代码:
<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>