wordpress ajax分页后打破10页

时间:2014-11-04 22:44:47

标签: ajax wordpress pagination

有人可以用ajax分页来帮助我,我已经2天了,但是无法理解。我有加载更多样式分页,这是代码,preety经典(下面)。 除非占位符到达第10页,否则一切都像刨光一样。然后,地狱就会松动,没有任何东西在加载。按钮仍然有效,直到达到maxpages,因此按钮被删除,但超过10个占位符没有任何反应。我正在使用此脚本的网站,您可以自己测试的地方是:http://filmhdonline.com/category/toate-filmele/ 我很感激有人知道我在说什么。提前谢谢。

jQuery(document).ready(function() {

    // The number of the next page to load (/page/x/).
    var pageNum = parseInt(pbd_alp.startPage);

    // The maximum number of pages the current query can return.
    var max = parseInt(pbd_alp.maxPages);

    // The link of the next page of posts.
    var nextLink = pbd_alp.nextLink; pageNum++;

    //Load more videos translation
    var more = pbd_alp.more;

    //Loading videos translation
    var loading = pbd_alp.loading;

    /**
     * Replace the traditional navigation with our own,
     * but only if there is at least one page of new posts to load.
     */

    if(pageNum <= max) {

       // Remove the traditional navigation.
        jQuery('.pagination').remove();

        // Insert the "More Posts" link.
        if( jQuery('#content').find('ul.listing-videos').length == 1 ){
            jQuery('#content ul.listing-videos').append('<li class="more-posts pbd-alp-placeholder-' + pageNum + '"></li>');
            jQuery('#content').append('<p id="pbd-alp-load-posts" class="pagination"><a href="#">' + more + '</a></p>');
        }

    }


    /**
     * Load new posts when the link is clicked.
     */
    jQuery('#pbd-alp-load-posts a').click(function() {

        // Are there more posts to load?
        if(pageNum <= max) {

            // Show that we're working.
            jQuery(this).text(loading);

            jQuery('.pbd-alp-placeholder-'+ pageNum).load(nextLink + ' #content ul.listing-videos li',
                function() {
                    //jQuery('.pbd-alp-placeholder-'+ pageNum).children('li').unwrap();                   
                    console.log(pageNum);

                    jQuery(this).children().hide();


                    $newContent = jQuery(this).children().unwrap();


                    $newContent.fadeIn('fast');

                    // Update page number and nextLink.
                    pageNum++;
                    nextLink = nextLink.replace(/\/page\/[0-9]?/, '/page/'+ pageNum);

                    **// Add a new placeholder, for when user clicks again.
                    jQuery('#content ul.listing-videos').append('<li class="more-posts pbd-alp-placeholder-'+ pageNum +'"></li>');**

                    // Update the button message.
                    if(pageNum <= max) {
                        jQuery('#pbd-alp-load-posts a').text('Vezi mai multe');
                    } else {
                        jQuery('#pbd-alp-load-posts a').remove();
                    }
                }
            );
        } else {
            jQuery('#pbd-alp-load-posts a').append('.');
        }   

        return false;
    });
});

2 个答案:

答案 0 :(得分:2)

对于wordpress中的ajax分页,您可以使用https://wordpress.org/plugins/wp-pagenavi/之类的插件。

OR

<div id="content">
<?php
$new_query = new WP_Query();
$new_query->query('post_type=post&showposts=1'.'&paged='.$paged);
?>

<?php while ($new_query->have_posts()) : $new_query->the_post(); ?>
<?php the_title(); ?>

<?php endwhile; ?>
    <div id="pagination">
        <?php next_posts_link('&laquo; Older Entries', $new_query->max_num_pages) ?>
        <?php previous_posts_link('Newer Entries &raquo;') ?>
    </div>
</div><!-- #content -->

<script>
jQuery(function($) {
    $('#content').on('click', '#pagination a', function(e){
        e.preventDefault();
        var link = $(this).attr('href');
        $('#content').fadeOut(500, function(){
            $(this).load(link + ' #content', function() {
                $(this).fadeIn(500);
            });
        });
    });
});
</script>

答案 1 :(得分:1)

我有同样的问题。 如果仍然发生,请替换:

nextLink = nextLink.replace(/\/page\/[0-9]?/, '/page/'+ pageNum);

nextLink = nextLink.replace(/\/page\/[0-9]*/, '/page/'+ pageNum);

错误的正则表达式问题[0-9]?仅匹配从1到9的单个数字。从10只需要1.而不是[0-9] *匹配从0到无穷大。因此,它在9之后(形式为0到9)中断,因为接下来的10并且它只需要使用1。