# Infinite Scroll and pagination problem

**URL:** <https://forum.getkirby.com/t/infinite-scroll-and-pagination-problem/3502>\
**Category:** Questions\
**Tags:** v2\
**Created:** [March 3, 2016, 10:07pm UTC](https://forum.getkirby.com/t/infinite-scroll-and-pagination-problem/3502 "2016-03-03T22:07:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![invasoria](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/invasoria/32/10898_2.png) [@invasoria](https://forum.getkirby.com/u/invasoria)\
**Post date:** [March 3, 2016, 10:07pm UTC](https://forum.getkirby.com/t/infinite-scroll-and-pagination-problem/3502/1 "2016-03-03T22:07:55Z")

</div>

Hello!

I’ve got a collection of pages with different templates stored in multiple subfolders as categories. This collection is then ordered by date and time. I reached the following solution to achieve this:

```
<?php
$cards = page('articles')->index()->visible()->filterBy('template', 'static.cards');
$video = page('articles')->index()->visible()->filterBy('template', 'static.video');
$post_a = page('articles')->index()->visible()->filterBy('template', 'post.a');
$post_b = page('articles')->index()->visible()->filterBy('template', 'post.b');
$totalContent = new Pages(array($cards, $video, $post_a, $post_b));
$totalContent = $totalContent->sortBy('fecha', 'asc', 'time', 'asc')->flip()->paginate(9);
$pagination = $totalContent->pagination();
?>

```

That worked as expected. I now have a collection with pagination.

I’ve managed to use the `<?php if(kirby()->request()->ajax()): ?>` function to structure all of my templates and make them work with Infinite Scroll and History.js in order to load a lot of content through AJAX.

Whenever the site is loaded from the root url, the pagination works as expected. Here’s the code for that part:

```
<?php if($pagination->hasPages()): ?>
  <nav class="pagination end">
	<?php if($pagination->hasNextPage()): ?>
	<a class="next" href="<?php echo $pagination->nextPageURL() ?>"></a>
	<?php else: ?>
<p> Congrats, you’ve reached the end of the internet. </p>
  <?php endif ?>
  </nav>
<?php endif ?>

```

The pagination link outputs as:

`<a class="next" href="/root-url/page;2"></a>`

The problem happens when I enter from a different link, let’s say, an article or post from the collection. A modal window is used to load the article while the post-loading feed stays the same way. In this case pagination outputs as:

`<a class="next" href="/root-url/articles/post-title-example/page;2"></a>`

This breaks the whole loading.

My question is: **How can I make a pagination always to point to the root url? Does the way I created the collection have something to do with this error?**

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:00pm UTC](https://forum.getkirby.com/t/infinite-scroll-and-pagination-problem/3502/2 "2025-02-06T17:00:02Z")

</div>


