php - 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>
解决方案
推荐阅读
- java - java - 如何在Java类中最好地存储来自CSV的数据?单个 Row 对象列表,还是具有嵌套对象的单个对象?
- python - 在 Django 中从购物车中删除单个产品
- node.js - Mongoose .save 方法有效但 Promise 返回错误
- python-3.x - pygame.error:视频系统未初始化
- python - 删除所有不是名词、动词、形容词、副词或专有名称的词。大蟒蛇
- java - quarkus 启动失败并出现 AppModel 初始化异常
- android - 使用“慢速测试卡。几分钟后拒绝”的 Android BillingClient 购买仍处于待处理状态
- android - 使用导航组件的多个后退堆栈 - 如何始终转到特定底部导航选项卡的起始目的地?
- snakemake - InputFunctionException - 扩展和输入函数未解析通配符
- javascript - 为什么我不能在主要功能中编写 console.log