The problem: 无限循环仅在用户登录后才起作用,然后显示尚未发布的帖子。一旦我注销,无限卷轴就不再工作了。
The setup: 我有以下自定义无限循环函数:
add_action(\'wp_ajax_zephyr_infinite_scroll\', \'zephyr_get_nextpage\');
function zephyr_get_nextpage() {
$loopFile = $_POST[\'loop_file\'];
$paged = $_POST[\'page_no\'];
$vv = stripslashes($_POST[\'vars\']);
$vars = json_decode($vv, true);
$vars[\'paged\'] = $paged;
global $isms;
global $zephyr_post_columns;
$zephyr_post_columns = $vars[\'columns\'];
unset($vars[\'columns\']);
$isms = $_POST[\'mas\'];
query_posts($vars);
global $wp_query;
if ( $wp_query->found_posts == 0 ) {
echo 0;
} else {
get_template_part( \'templates/\'.$loopFile );
}
exit;
}
那么我的
loop.php
文件:
<?php global $zephyr_cont;
global $zephyr_post_layout;
global $zephyr_i;
global $isms;
global $zephyr_post_columns;
$zephyr_i = 0;
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php
if ( $isms == \'true\' ) {
$zephyr_i++;
get_template_part( \'templates/post\', \'masonry\'.get_post_format() );
} else {
get_template_part( \'templates/post\', get_post_format() );
}
endwhile; else : ?>
<h2><?php _e(\'No posts found, go \', \'zephyr\'); ?> <a href="<?php echo home_url(); ?>" title="<?php bloginfo(\'name\'); ?>"><?php _e(\'home\', \'zephyr\'); ?></a>?</h2>
<?php endif; ?>
以及
script.js
文件:
function loadArticle(pageNumber) {
$(\'#ajaxload\').fadeIn(300);
$.ajax({
url: Zephyr.ajaxurl,
type:\'POST\',
data: {
action : \'zephyr_infinite_scroll\',
page_no : pageNumber,
loop_file : \'loop\',
vars : Zephyr.queryvars,
mas : isms
},
success: function(html){
if ( html !== \'0\' ) {
if ( isms ) {
$zephyr_container.isotope( \'insert\', $(html) );
} else {
$(html).hide().appendTo(\'#content\').fadeIn(\'300\');
}
layoutSidebar(ms);
} else {
noload = 1;
}
$(\'#ajaxload\').fadeOut(300);
}
});
return false;
}