Problems with Infinite scroll in WordPress

2

I am using a plugin for WordPress called Flex Mag Option , one of its features is that it adds a infinite_scroll (infinite displacer) to the initial page. This is not very customizable from the theme settings panel. So I had to enter the code to try to fix an error that causes the posts that are loaded to be repeated. Let me explain:

A list of posts (5 posts) and a see more button are displayed, which when clicked must display more posts below those already shown. But they are showing again the same ones that already appeared.

The button uses a function called pagination , below the main code I will leave the function.

Here is the code for the part in question:

<ul class="blog-widget-list left relative infinite-content">
    <?php if (isset($do_not_duplicate)) { ?>
        <?php global $post; $mvp_posts_num = esc_html(get_option('mvp_posts_num')); $paged = (get_query_var('page')) ? get_query_var('page') : 1; query_posts(array( 'posts_per_page' => $mvp_posts_num, 'post__not_in'=>$do_not_duplicate, 'paged' =>$paged )); if (have_posts()) : while (have_posts()) : the_post(); ?>
        <li class="infinite-post">

            <a href="<?php the_permalink(); ?>" rel="bookmark">
            <?php if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail())  ) { ?>
                <div class="blog-widget-img left relative">
                    <?php the_post_thumbnail('mvp-mid-thumb', array( 'class' => 'reg-img' )); ?>
                    <?php the_post_thumbnail('mvp-small-thumb', array( 'class' => 'mob-img' )); ?>
                    <?php $post_views = get_post_meta($post->ID, "post_views_count", true); if ( $post_views >= 1) { ?>
                    <div class="feat-info-wrap">
                        <div class="feat-info-views">
                            <i class="fa fa-eye fa-2"></i> <span class="feat-info-text"><?php mvp_post_views(); ?></span>
                        </div><!--feat-info-views-->
                        <?php $disqus_id = get_option('mvp_disqus_id'); if ( ! $disqus_id ) { if (get_comments_number()==0) { } else { ?>
                            <div class="feat-info-comm">
                                <i class="fa fa-comment"></i> <span class="feat-info-text"><?php comments_number( '0', '1', '%' ); ?></span>
                            </div><!--feat-info-comm-->
                        <?php } } ?>
                    </div><!--feat-info-wrap-->
                    <?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><!--blog-widget-img-->
            <?php } ?>
            <div class="blog-widget-text left relative">
                <span class="side-list-cat"><?php $category = get_the_category(); echo esc_html( $category[0]->cat_name ); ?></span>
                <h2><?php the_title(); ?></h2>
                <p><?php echo wp_trim_words( get_the_excerpt(), 22, '...' ); ?></p>
            </div><!--blog-widget-text-->
            </a>
        </li>
        <?php endwhile; endif; ?>


    <?php } else { ?>
        <?php $mvp_posts_num = esc_html(get_option('mvp_posts_num')); $paged = (get_query_var('page')) ? get_query_var('page') : 1; query_posts(array( 'posts_per_page' => $mvp_posts_num, 'paged' =>$paged )); if (have_posts()) : while (have_posts()) : the_post(); ?>
        <li class="infinite-post">

            <a href="<?php the_permalink(); ?>" rel="bookmark">
            <?php if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail())  ) { ?>
                <div class="blog-widget-img left relative">
                    <?php the_post_thumbnail('mvp-mid-thumb', array( 'class' => 'reg-img' )); ?>
                    <?php the_post_thumbnail('mvp-small-thumb', array( 'class' => 'mob-img' )); ?>
                    <?php $post_views = get_post_meta($post->ID, "post_views_count", true); if ( $post_views >= 1) { ?>
                    <div class="feat-info-wrap">
                        <div class="feat-info-views">
                            <i class="fa fa-eye fa-2"></i> <span class="feat-info-text"><?php mvp_post_views(); ?></span>
                        </div><!--feat-info-views-->
                        <?php $disqus_id = get_option('mvp_disqus_id'); if ( ! $disqus_id ) { if (get_comments_number()==0) { } else { ?>
                            <div class="feat-info-comm">
                                <i class="fa fa-comment"></i> <span class="feat-info-text"><?php comments_number( '0', '1', '%' ); ?></span>
                            </div><!--feat-info-comm-->
                        <?php } } ?>
                    </div><!--feat-info-wrap-->
                    <?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><!--blog-widget-img-->
            <?php } ?>
            <div class="blog-widget-text left relative">
                <span class="side-list-cat"><?php $category = get_the_category(); echo esc_html( $category[0]->cat_name ); ?></span>
                <h2><?php the_title(); ?></h2>
                <p><?php echo wp_trim_words( get_the_excerpt(), 22, '...' ); ?></p>
            </div><!--blog-widget-text-->
            </a>
        </li>
        <?php endwhile; endif; ?>
    <?php } ?>
</ul>
<?php $mvp_infinite_scroll = get_option('mvp_infinite_scroll'); 
if ($mvp_infinite_scroll == "true") { 
    if (isset($mvp_infinite_scroll)) { ?>
<a href="#" class="inf-more-but">Ver más</a>
<?php } } ?>
<div class="nav-links">
    <?php if (function_exists("pagination")) { pagination($wp_query->max_num_pages); } ?>
</div><!--nav-links-->

Pagination:

if ( !function_exists( 'pagination' ) ) {
    function pagination($pages = '', $range = 4)
    {
         $showitems = ($range * 2)+1;

         global $paged;
         if(empty($paged)) $paged = 1;

         if($pages == '')
         {
             global $wp_query;
             $pages = $wp_query->max_num_pages;
             if(!$pages)
             {
                 $pages = 1;
             }
         }

         if(1 != $pages)
         {
             echo "<div class=\"pagination\"><span>".__( 'Page', 'mvp-text' )." ".$paged." ".__( 'of', 'mvp-text' )." ".$pages."</span>";
             if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo; ".__( 'First', 'mvp-text' )."</a>";
             if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; ".__( 'Previous', 'mvp-text' )."</a>";

             for ($i=1; $i <= $pages; $i++)
             {
                 if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
                 {
                     echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
                 }
             }

             if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">".__( 'Next', 'mvp-text' )." &rsaquo;</a>";
             if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>".__( 'Last', 'mvp-text' )." &raquo;</a>";
             echo "</div>\n";
         }
    }
}
    
asked by Bryan Calvo Benoit 07.11.2016 в 03:16
source

0 answers