新闻帖的预加载已停止工作

时间:2017-05-11 14:08:37

标签: javascript jquery

我很抱歉,如果这是一个悬而未决的问题,但在这里有一个页面:http://ideedev.co.uk/newseed/news/当你向下滚动时,它应该在底部预加载其余的帖子 - 目前它只是看起来像装载而没有找到任何东西......

此处网站的原始版本:http://www.seedcreativity.co.uk/news/效果很好......但我无法弄清楚为什么会这样,而我的不行。

帖子模板上不起作用的代码是:

<!-- Main Content -  Blogs Posts
    –––––––––––––––––––––––––––––––––––––––––––––––––– -->

    <section id="posts" class="wrapper">

        <?php
        global $wp_query;

        while(have_posts()) {
            the_post();
            $post = new SeedPost(get_the_ID());

            if($wp_query->found_posts < 3) {
                $post->display(true);
            } else{
                $post->display();
            }
        }
        ?>

    </section><!-- End of Section - Blogs Posts & Media content -->



    <?php if($wp_query->found_posts > get_option('posts_per_page')): ?>
    <div class="load-more" data-posts_per_page="<?php echo get_option('posts_per_page'); ?>" data-nonce="<?php echo wp_create_nonce('load_more_posts'); ?>">
        <div class="preloader">
            <div class="preloader--center">
                <div class="preloader--center--absolute">
                    <div id="preloader__object__one" class="preloader__object"></div>
                    <div id="preloader__object__two" class="preloader__object"></div>
                    <div id="preloader__object__three" class="preloader__object"></div>
                    <div id="preloader__object__four" class="preloader__object"></div>
                </div>
            </div>
        </div>
        <span class="load-more__icon">+</span>

        <p class="load-more__msg"> Get next posts</p>
    </div>
    <?php endif; ?>

我认为这是处理它的.js:

;(function ($) {

    $.fn.newsArchive = function () {

        var $body = this,
            $postsContainer = $body.find('#posts'),
            $loadMoreButton = $body.find('.load-more'),
            postsPerPage = $loadMoreButton.data('posts_per_page'),
            offset = postsPerPage,
            nonce = $loadMoreButton.data('nonce'),
            busy = false;

        var loadMore = function () {
            if(!busy && !$loadMoreButton.hasClass('no-more-posts')) {
                busy = true;
                $loadMoreButton.addClass('loading');

                $.get('/', {
                    load_more_posts: nonce,
                    offset:          offset
                }, function (response) {
                    if(typeof response.html !== 'undefined') {
                        $postsContainer.append(response.html);
                        offset += postsPerPage
                    }

                    if(typeof response.posts_remaining !== 'undefined' && response.posts_remaining == 0) {
                        $loadMoreButton.addClass('no-more-posts');
                        $loadMoreButton.find('.load-more__msg').text('No more posts');
                    }

                    busy = false;
                    $loadMoreButton.removeClass('loading');
                }, 'json');
            }
        };

        $loadMoreButton.on('click', function () {
            loadMore();
        });

        $(window).on('scroll', function() {
            if(($(window).scrollTop() + $(window).height()) == $(document).height()) {
                loadMore();
            }
        });

        return this;

    };


})(jQuery);

由于

0 个答案:

没有答案