我在我们网站的主页上使用 JetPack 的 Infinite Scroll,它工作正常,但我也想在那里显示某些帖子。
如果帖子显示在无限循环之外,我希望将其从无限循环中删除,以免重复。
我使用 bm_ignoreposts 设置了一个全局数组,并将其添加到无限循环渲染中,但由于某种原因它无法正常工作。这是代码。
函数.php
无限渲染器。
add_filter( 'infinite_scroll_archive_supported', 'tweakjp_custom_is_support' );
function mm_infinite_scroll_render() {
global $post;
while ( have_posts() ) : the_post();
bm_ignorePost($post->ID);
get_template_part( 'content-inf' );
endwhile;
}
查询
function mm_infinite_scroll_query_args($args) {
$new_args = array(
'posts_per_page' => $args['posts_per_page'],
'paged' => $args['paged'],
'orderby' => 'date',
'order' => 'DESC',
'post_type' => array( 'post', 'features', 'it_hardware', 'videos' ),
'post_status' => 'publish',
);
return $new_args;
}
此处参考忽略帖子代码:
function bm_ignorePost ($id) {
if (!is_page()) {
global $bmIgnorePosts;
$bmIgnorePosts[] = $id;
}
}