我一直试图让无限滚动工作,但似乎无法让它工作。
我在帖子循环中有三个文件content-post-ft.php
,the functions.php
然后是加载帖子的首页frontpage.php
函数.php
add_theme_support( 'infinite-scroll', array(
'container' => 'main-content',
'type' => 'scroll',
'footer' => 'foot',
'render' => 'infinite_scroll_render'
));
function infinite_scroll_render() {
get_template_part( 'content-post-ft', 'standard' );
}
内容-post-ft.php
<div class="hub-cont">
<?php
$thumb_id = get_post_thumbnail_id();
$thumb_url_array = wp_get_attachment_image_src($thumb_id, 'thumbnail-size', true);
$thumb_url = $thumb_url_array[0];
?>
<div id="newsitem">
<div id="newsimg" style="background-image: url('<?php echo $thumb_url ?>')">
<a href="<?php the_permalink(); ?>"></a>
</div>
<div id="newsname"> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> </div>
<div id="newstext"><?php $text = $post->post_content; $trimmed = wp_trim_words( $text, 40, null ); echo $trimmed; ?></div>
<div class="clear"></div>
</div>
<?php
// endwhile;
// endif;
wp_reset_postdata();?>
</div>
Frontpage.php
<div id="main-content">
<?php
$myargs = array (
//'showposts' => 2,
'post_type' => 'post',
'category_name' => 'News'
);
$myquery = new WP_Query($myargs);
if($myquery->have_posts() ) :
while($myquery->have_posts() ) : $myquery->the_post();
get_template_part( 'content-post-ft', get_post_format() );
endwhile;
endif;
?>
</div>
我试过看很多教程和其他有类似问题的人,但似乎没有任何效果。
由于循环,该页面显示了 10 个帖子,但它只是添加了 10 个并且没有“滚动”
解决这个问题真的会帮助我缓解压力!