2012-04-03 61 views
0

這是我以前的帖子的後續,現在用不同的代碼。當沒有更多的帖子加載時,隱藏「加載更多」鏈接

我得到了這個工作,它加載了我想要的內容,所有頁面(請參閱previous post)。我有9個頁面(標準的WP檔案,我用next_posts_link作爲點擊的「錨點」。)

但是,當頁面9加載時,我點擊「加載更多」並繼續加載第9頁....我想要它停下來隱藏「加載更多」鏈接。任何幫助非常讚賞。

jQuery(document).ready(function($) { 
var $content = '#upplevelser'; 
var $nav_wrap = '.navigation'; 
var $anchor = '.navigation .nav-previous a'; 
var $text = 'Load More'; 
var $next_href = $($anchor).attr('href'); // Get URL for the next set of posts 
$($nav_wrap).html('<a id="nav-below" href="' + $next_href + '">' + $text + '</a>'); 
$('#nav-below a').click(function(e) { 
    e.preventDefault(); 

if(jQuery(this).attr("href") == "") { 
    alert('I am empty href value'); 
    } 

    $.get($(this).attr('href'), '', function(data) { 
    var $timestamp = new Date().getTime(); 
    var $new_content = $($content, data).wrapInner('<div class="more-articles-here" id="rtz-' + $timestamp + '" />').html(); // Grab just the content 
    $next_href = $($anchor, data).attr('href'); // Get the new href 
    $($nav_wrap).before($new_content); // Append the new content 
    $('#rtz-' + $timestamp).hide().fadeIn('slow'); // Animate load 
    $('#nav-below a').attr('href', $next_href); // Change the next URL 
    $('.more-articles-here ' + $nav_wrap).remove(); // Remove the original navigation 

    }); 
}); 
}); 

回答

0

我已經修改了你的代碼一點點,以滿足您的要求,其在我的本地安裝好....

這裏我用過的已使用過。

jQuery(document).ready(function($) { 
var $content = '#upplevelser'; 
var $nav_wrap = '.navigation'; 
var $anchor = '.navigation .nav-previous a'; 
var $text = 'Load More'; 
var $next_href = $($anchor).attr('href'); // Get URL for the next set of posts 
$($nav_wrap).html('<a id="nav-below" href="' + $next_href + '">' + $text + '</a>'); 
$('#nav-below a').click(function(e) { 
    e.preventDefault(); 

if(jQuery(this).attr("href") == "") { 
    alert('I am empty href value'); 
    } 

    $.get($(this).attr('href'), '', function(data) { 
    var $timestamp = new Date().getTime(); 
    var $new_content = $($content, data).wrapInner('<div class="more-articles-here" id="rtz-' + $timestamp + '" />').html(); // Grab just the content 
    $next_href = $($anchor, data).attr('href'); // Get the new href 
    $($nav_wrap).before($new_content); // Append the new content 
    $('#rtz-' + $timestamp).hide().fadeIn('slow'); // Animate load 
    $('#nav-below a').attr('href', $next_href); // Change the next URL 
    $('.more-articles-here .navigation:last').remove(); // Remove the original navigation 

    }); 
}); 
}); 

希望這會對你有用......