我正在使用以下JavaScript在#work\\u项目中加载更多页面(请参阅live athttp://mtthwbsh.com):
jQuery(document).ready(function($){
$(\'.older a\').live(\'click\', function(e) {
e.preventDefault();
$(\'.navigation\').prepend("<div class=\\"loader\\"> </div>");
var link = jQuery(this).attr(\'href\');
var $content = \'#work_items\';
var $nav_wrap = \'.navigation\';
var $anchor = \'.navigation .older a\';
var $next_href = $($anchor).attr(\'href\'); // Get URL for the next set of posts
$.get(link+\'\', function(data){
var $timestamp = new Date().getTime();
var $new_content = $($content, data).wrapInner(\'\').html(); // Grab just the content
$(\'.navigation .loader\').remove();
$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
$(\'.older a\').attr(\'href\', $next_href); // Change the next URL
$(\'#work_items .navigation:last\').remove(); // Remove the original navigation
});
});
});
当前,如果您位于帖子的最后一页,并再次单击“加载更多”,则会再次加载相同的最后一页。如果没有留下任何页面,我希望有条件地不运行该函数(并将按钮替换为“无更多帖子”)。我该怎么做呢?以下是我用于分页的标记:
<div id="work_items">
<?php $paged = (get_query_var(\'page\')) ? get_query_var(\'page\') : 1;
$args=array(\'category_name\'=>\'portfolio\',\'posts_per_page\'=>4,\'paged\'=>$paged
);
query_posts($args); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="box">
<div class="thumbnail">
<a href="<?php the_permalink(); ?>">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
?>
</a>
</div><!-- THUMBNAIL -->
<aside>
<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
</aside><!-- ASIDE -->
</div><!-- BOX -->
<?php endwhile; ?>
我面临的另一个不相关的问题是,我每四篇文章都会有第n个孩子(4n)来填补空白,但由于某种原因,在第一组文章之后,它开始针对下一组的第一篇文章。WordPress处理元素顺序的方式有什么奇怪的地方吗?
谢谢你的帮助!