加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 无限滚动启用(wordpress)

发布时间:2020-12-13 15:57:36 所属栏目:PHP教程 来源:网络整理
导读:所以,我发现本教程启用无限滚动: http://wptheming.com/2012/03/infinite-scroll-to-wordpress-theme/ 基本上我需要有js文件并将以下内容添加到function.php中 /** * Infinite Scroll */function custom_infinite_scroll_js() { if( ! is_singular() ) { ?
所以,我发现本教程启用无限滚动: 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' => __( '&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而不是更可靠,更快速的类

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读