2014-11-04 67 views
2

有人可以幫助我與阿賈克斯分頁請,我已經2天了,無法弄清楚。我已經加載更多風格分頁,這是代碼,preety經典(下面)。 除了當佔位符到達第10頁時,所有東西都可以用作刨削。然後,地獄破裂,沒有東西再加載了。該按鈕仍然有效,直到maxpages已到達,因此該按鈕被刪除,但超過10個佔位符沒有任何反應。我正在使用這個腳本的網站,你可以測試自己的地方是這樣的:http://filmhdonline.com/category/toate-filmele/ 我希望有人有一個ideea我在說什麼。提前致謝。wordpress ajax分頁後10頁

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

對於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> 
+0

這個是主題的一部分,我儘可能保持與插件的距離。 – 2014-11-05 10:27:06

+0

@VartolomeiEduardClaudiu根據以上評論更改代碼 – 2014-11-05 10:47:10

+0

sory,不想被粗魯,完全改變我可以隨時做的代碼,但隨後我必須重新制作主題的所有CSS,這是一種痛苦。我現在的工作是99%,問題是當你到達plaheholder 10,11,12它不再顯示任何東西。我留下了一個網址,以便您可以測試我在說什麼。我真的不想重寫代碼。雖然不是我所喜歡的,但謝謝你的回答。 – 2014-11-05 18:44:14

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.

+0

是答案?很難說。 – 2016-02-02 18:18:01