所以,我发现本教程启用无限滚动:http://wptheming.com/2012/03/infinite-scroll-to-wordpress-theme/
基本上我需要有js文件并将以下内容添加到function.PHP中
/**
* Infinite Scroll
*/
function custom_infinite_scroll_js() {
if( ! is_singular() ) { ?>
<script>
var infinite_scroll = {
loading: {
img: "<?PHP echo get_template_directory_uri(); ?>/images/ajax-loader.gif",
msgText: "<?PHP _e( 'Loading the next set of posts...', 'custom' ); ?>",
finishedMsg: "<?PHP _e( 'All posts loaded.', 'custom' ); ?>"
},
"nextSelector":"#nav-below .nav-prevIoUs a",
"navSelector":"#nav-below",
"itemSelector":"article",
"contentSelector":"#content"
};
jQuery( infinite_scroll.contentSelector ).infinitescroll( infinite_scroll );
</script>
<?PHP
}
}
add_action( 'wp_footer', 'custom_infinite_scroll_js',100 );
我需要更改以下参数:
> img:ajax加载程序映像的路径
> nextSelector:“以前的帖子”链接的选择器.
> navSelector:包含上一个/下一个导航链接的选择器.
> itemSelector:帖子的选择器.这可能是.hentry,.post,.etc
> contentSelector:包含帖子的div.
好吧,我被卡住了.
这是我的PHP:
$defaults = array(
'base' => add_query_arg( 'paged', '%#%' ),
'format' => '',
'total' => $max_num_pages,
'current' => $current,
'prev_next' => true,
'prev_text' => __( '←',my_site),
'next_text' => __( '→',my_site),
'show_all' => false,
'end_size' => 1,
'mid_size' => 1,
'add_fragment' => '',
'type' => 'plain',
'before' => '<div class="pagination">',
'after' => '</div>',
'echo' => true,
'use_search_permastruct' => true
);
这是我目前得到的html输出:
<div class="pagination">
<a class="prev page-numbers" href="example.com/dfgdg/page/2/">←</a>
<a class="page-numbers" href="http://example.com/dfgdg/page/1/">1</a>
<a class="page-numbers" href="http://example.com/dfgdg/page/2/">2</a>
<span class="page-numbers current">3</span>
<a class="page-numbers" href="http://example.com/dfgdg/page/4/">4</a>
<span class="page-numbers dots">…</span>
<a class="page-numbers" href="example.com/dfgdg/page/20/">20</a>
<a class="next page-numbers" href="example.com/dfgdg/page/4/">→</a>
</div>
有人可以帮我解决这个问题吗?
要么
我应该考虑采用不同的方法吗?
谢谢一堆!
EM
解决方法:
基本上这里出现的问题是你在不理解底层代码的情况下复制粘贴.
在您添加到PHP的JS片段中,您将添加无限滚动应该起作用的元素(contentSelector)
在示例中,它设置为“#content”,但在您的代码中应该是“.pagination”.
所以,如果你改变contentSelector它应该工作:)
编辑:
我建议您将PHP中的“before”更改为id =“pagination”.这可能会破坏您的模板,因此请确保使用不同的页面对其进行测试,但这样您就可以选择id而不是更可靠,更快速的类