php – 无限滚动启用(wordpress)

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 无限滚动启用(wordpress)脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
所以,我发现本教程启用无限滚动: 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' => __( '&amp;larr;',my_site),'next_text' => __( '&rarr;','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而不是更可靠,更快速的类

脚本宝典总结

以上是脚本宝典为你收集整理的php – 无限滚动启用(wordpress)全部内容,希望文章能够帮你解决php – 无限滚动启用(wordpress)所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。