当没有更多帖子加载时,隐藏“加载更多”链接

时间:2012-04-03 15:58:42

标签: jquery

这是对我上一篇文章的跟进,现在有不同的代码。

我有这个工作,它加载我想要的内容,所有页面(见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

    });
});
});

1 个答案:

答案 0 :(得分:0)

我已经修改了你的代码以适应你的要求,并且在我的localhost安装上很好..

这是我用过的。

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

    });
});
});

希望这对你也有用......

相关问题