重复发帖如何解决此问题

时间:2016-08-09 作者:pradeepkumar1565

在主页中,它会正确加载更多帖子。但是当我使用相同的代码加载更多的帖子时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>  

enter image description here

1 个回复
最合适的回答,由SO网友:pradeepkumar1565 整理而成

我找到了解决办法。我删除此$paged=(get\\u query\\u var(\'第页‌​\')) ? get\\u query\\u var(\'页\'‌​) : 1.从现在的查询来看,它工作正常,无需重复帖子。

相关推荐

如何修改WP_INCLUDE/BLOCKS/LATEST_posts.php

我是WordPress开发的初学者,希望得到一些帮助。我在一个简单的WordPress网站上工作。基本上,用户希望在主页上显示最新的帖子。我使用了最新帖子块,并将其设置为显示整个帖子内容,现在用户不希望帖子标题链接到单个帖子页面(因为帖子的内容显示在主页上)。如何安全地修改模板文件,使其像h2标记一样使用,而不是在主题中使用的href标记。我知道您可以创建子主题并修改wp_content 文件,但我不确定如何处理中的文件wp_include. 我读到一些关于修改functions.php 但我不确定,如果