首页 > 解决方案 > Jetpack 无限滚动在首页中不起作用

问题描述

我正在研究一个具有帖子类型的主题 - “旅游”。

我正在使用 JetPack 的无限滚动来呈现新帖子:

函数.php

            function tweakjp_custom_is_support() {
                $supported = current_theme_supports( 'infinite-scroll' ) && ( is_home() || is_front_page() ||  is_archive() || is_single());

                return $supported;
            }
            add_filter( 'infinite_scroll_archive_supported', 'tweakjp_custom_is_support' ); 

            function my_child_infinite_scroll_render() {
                while ( have_posts() ) : the_post();
                    get_template_part( 'content', get_post_type());
                endwhile;
            }

            function my_child_setup() {
                add_theme_support( 'infinite-scroll', array(
                    'type'           => 'scroll',
                    'container'      => 'mob_infinite',
                    'render'         => 'my_child_infinite_scroll_render',
                    'posts_per_page' => 2,
                ) );
            }

            add_action( 'after_setup_theme', 'my_child_setup' );

首页

            <div class="container">
                <div id="mob_infinite">
                    $args = array ('post_type' => 'post');

                    $myquery = new wp_query($args);

                    if($myquery->have_posts() ){
                        while($myquery->have_posts() ) : $myquery->the_post();

                            get_template_part( 'content', get_post_type() );

                        endwhile;
                    } 
                </div>
            </div>

标签: phpwordpressinfinite-scrolljetpack

解决方案


推荐阅读