0

我在我们网站的主页上使用 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;
    }
}
4

1 回答 1

0

我决定不再使用 JetPack,而是使用自定义 Javascript 版本,它使用 AJAX 加载运行新查询的新帖子。

在与 Jetpack 支持人员交谈后,他们认为根据插件的工作方式是不可能的。

于 2015-10-19T21:59:35.060 回答