当没有更多的帖子加载时,隐藏“加载更多”链接
问题描述:
这是我以前的帖子的后续,现在用不同的代码。当没有更多的帖子加载时,隐藏“加载更多”链接
我得到了这个工作,它加载了我想要的内容,所有页面(请参阅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
});
});
});
答
我已经修改了你的代码一点点,以满足您的要求,其在我的本地安装好....
这里我用过的已使用过。
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
});
});
});
希望这会对你有用......