我想首先为这篇文章这么长表示歉意,但我觉得它可能会帮助其他人,因为我有这个问题,我想我最好尽可能详细。
我有一个问题,这是循环。php文件多次加载同一帖子,我尝试了防止重复帖子的方法,但没有任何效果。正如您在下面看到的,我正在加载要发布到ajax函数中的函数,我得到了一个成功的调用,但此时我不确定循环文件是否是问题所在。当站点第一次加载时,它加载第一组帖子,然后当它获得第二组帖子时,它很好,但之后的所有内容都是相同的帖子,它就像加载循环文件,但查询被卡住了。
有什么建议吗?非常感谢您的帮助。
环php文件
<div class="post-left">
<?php query_posts(array(\'post__not_in\' => $id_merge,\'posts_per_page\'=>\'2\'));
$do_not_duplicate = $post->ID;
if (have_posts()) : while (have_posts()) : the_post();
if( $post->ID == $do_not_duplicate ) continue;
$ids[] = get_the_ID(); ?>
<div class="images-grid-page-wrapper">
<?php the_title(); ?>
</div>
<?php endwhile; endif; // End the loop. Whew. ?>
</div>
<div class="post-mid">
<?php query_posts(array(\'post__not_in\' => $id_merge,\'posts_per_page\'=>\'3\'));
$do_not_duplicate = $post->ID;
if (have_posts()) : while (have_posts()) : the_post();
if( $post->ID == $do_not_duplicate ) continue;
$ids[] = get_the_ID(); ?>
<div class="images-grid-page-wrapper">
<?php the_title(); ?>
</div>
<?php endwhile; endif; // End the loop. Whew. ?>
</div>
功能。phpadd_action(\'wp_ajax_infinite_scroll\', \'wp_infinitepaginate\'); // for logged in user
add_action(\'wp_ajax_nopriv_infinite_scroll\', \'wp_infinitepaginate\'); // if user not logged in
function wp_infinitepaginate(){
$loopFile = $_POST[\'loop_file\'];
get_template_part( $loopFile );
exit;
}
阿贾克斯jQuery(document).ready(function($) {
var count = 1;
var total = <?php echo $wp_query->max_num_pages; ?>;
$(window).scroll(function(){
if ($(window).scrollTop() == $(document).height() - $(window).height()){
if (count > total){
return false;
}else{
loadArticle(count);
}
count++;
}
});
function loadArticle(){
$(\'a#inifiniteLoader\').show(\'fast\');
$.ajax({
url: "<?php bloginfo(\'wpurl\') ?>/wp-admin/admin-ajax.php",
type:\'POST\',
data: "action=infinite_scroll&loop_file=loop",
success: function(html){
$(\'a#inifiniteLoader\').hide(\'1000\');
$("#content").append(html); // This will be the div where our content will be loaded
}
});
return false;
}
});