简体   繁体   English

WordPress single.php中的小故障无限滚动/分页循环

[英]Glitch in WordPress single.php Infinite Scroll/Pagination Loop

I've created a quick pagination on a single.php file in order to use infinite scroll in a loop at the bottom of the page. 我已经在single.php文件上创建了快速分页,以便在页面底部的循环中使用无限滚动。 Here's the code I used to create my 'nextSelector' and 'navSelector' for the infinite scroll: 这是我用来为无限滚动创建“ nextSelector”和“ navSelector”的代码:

<?php
    $next_url = $_SERVER['REQUEST_URI'].'2';
?>

<ul class="single-pagination">         
     <li><a class="next pagination-item" href="<?php echo $next_url; ?>/">Next</a></li>
</ul><!--single-pagination-->

This works fine because it creates the 'next ' page to get the infinite scroll started. 这很好,因为它创建了“下一个”页面以开始无限滚动。 My navSelector in the infinite scroll is ul.single-pagination and my nextSelector is a.next.pagination-item . navSelector在无限滚动是ul.single-pagination和我nextSelectora.next.pagination-item This all works fine on most pages but when I visit a page that has a number at the end of the URL, the infinite scroll changes the number instead of changing the appended number on the URL. 这在大多数页面上都可以正常工作,但是当我访问URL末尾带有数字的页面时,无限滚动将更改该数字,而不是更改URL上的附加数字。 For example, if I had a URL like this: 例如,如果我有这样的网址:

http://www.example.com/this-post-2/

It would load the first iteration of the infinite scroll successfully, which would be: 它将成功加载无限滚动的第一次迭代,这将是:

http://www.example.com/this-post-2/2/

and then on the next iteration would throw a 404 error on this URL: 然后在下一次迭代中将在此URL上引发404错误:

http://www.example.com/this-post-3/2/

Though it should be looking for: 虽然它应该寻找:

http://www.example.com/this-post-2/3/

Short of breaking apart the JS code for the infinite scroll, is there any way to customize the URL that the infinite scroll look for? 除了分解无限滚动的JS代码之外,还有什么方法可以自定义无限滚动要查找的URL?

EDIT 编辑

This is related to the RegEx expression in the jquery.infinitescroll.min.js that is altering the URL. 这与jquery.infinitescroll.min.js中的RegEx表达式有关,该表达式正在更改URL。 Here is the code that I am working on altering. 这是我正在修改的代码。 I will post the answer here if no one beats me to it: 如果没有人击败我,我将在这里发布答案:

t = t.match(/^(.*?)\b2\b(.*?$)/).slice(1);

The solution to this lies in the jquery.infinitescroll.js (or jquery.infinitescroll.min.js file). 解决方案在于jquery.infinitescroll.js(或jquery.infinitescroll.min.js文件)。 The RegEx that the author used on this does not take into account these types of URLs. 作者为此使用的RegEx没有考虑这些类型的URL。

I created a fork of the code in my GitHub account that can be accessed here: 我在GitHub帐户中创建了代码的分支,可在此处访问:

https://github.com/MillerMedia/infinite-scroll https://github.com/MillerMedia/infinite-scroll

Basically, a RegEx expression of this: 基本上,这是一个RegEx表达式:

t = t.match(/^(.*?2)\b2\b(.*?$)/).slice(1);

Is placed before this one: 放在此之前:

t = t.match(/^(.*?)\b2\b(.*?$)/).slice(1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM