如何为博客和自定义文章类型在wordpress中创建无限滚动。我尝试过jetpack无限滚动,但它不工作自定义wordpress页面模板的自定义post类型。我看过这个教程,但它似乎很古老。
http://code.tutsplus.com/tutorials/how-to-create-infinite-scroll-pagination--wp-24873
也看了这个https://github.com/infinite-scroll/infinite-scroll,但是这个项目已经不再维护了。
请告诉我或推荐一些新的教程,是兼容Wordpress 4.5创建无限滚动。
谢谢
发布于 2016-05-15 17:31:06
您可能需要定义一个新的循环函数,以便自定义Post类型传递到render参数。
如https://jetpack.com/support/infinite-scroll/中的示例所示
/**
* Add theme support for infinity scroll
*/
function twenty_ten_infinite_scroll_init() {
add_theme_support( 'infinite-scroll', array(
'container' => 'content',
'render' => 'twenty_ten_infinite_scroll_render',
'footer' => 'wrapper',
) );
}
add_action( 'after_setup_theme', 'twenty_ten_infinite_scroll_init' );
/**
* Set the code to be rendered on for calling posts,
* hooked to template parts when possible.
*
* Note: must define a loop.
*/
function twenty_ten_infinite_scroll_render() {
get_template_part( 'loop' );
}如您所见,您可以在该函数中调用一个模板部件来生成要显示的下一个帖子负载(Infinite将为您更新查询,因此您只需要一个循环模板)。
https://wordpress.stackexchange.com/questions/226692
复制相似问题