# Pagination link throws error 404

**URL:** <https://forum.getkirby.com/t/pagination-link-throws-error-404/10622>\
**Category:** Questions\
**Tags:** v2\
**Created:** [June 14, 2018, 7:48am UTC](https://forum.getkirby.com/t/pagination-link-throws-error-404/10622 "2018-06-14T07:48:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![polyester](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@polyester](https://forum.getkirby.com/u/polyester)\
**Post date:** [June 14, 2018, 7:48am UTC](https://forum.getkirby.com/t/pagination-link-throws-error-404/10622/1 "2018-06-14T07:48:10Z")

</div>

Hi there.

**My problem:**  
I have a `blog.php` template (and a `blog.php` controller) who displays my blogposts or sort them per category.

When i reach my pagination limit i can see my pagination nav but get a 404 error when i click on _older posts_.  
My category list then shows the pagination too, even if the pagination limit is not reached for the displayed articles per category.

There is no error in debug mode.

**My code:**  
I have the following code in my template `blog.php`:

```
<?php if($pagination->hasPages()): ?>
  <nav class="pagination">
    <?php if($pagination->hasNextPage()): ?>
    <a href="<?= $pagination->nextPageURL() ?>" class="pagination__older">Ältere Einträge</a>
    <?php endif ?>
    <?php if($pagination->hasPrevPage()): ?>
    <a href="<?= $pagination->prevPageURL() ?>" class="pagination__newer">Neuere Einträge</a>
    <?php endif ?>
  </nav>
<?php endif ?>

```

Then i have the controller `blog.php`:

```
<?php

return function($site, $pages, $page) {

  // Kategorien
  $category = urldecode(param('category'));
  $articlesByCategory = $pages->index()
                              ->visible()
                              ->filterBy('category', $category)
                              ->flip()
                              ->paginate(10);

  // Artikel
  $articles = $pages->index()
                    ->visible()
                    ->filterBy('template', 'post.article' && 'post.link' && 'post.image' && 'post.status')
                    ->flip()
                    ->paginate(10);

  return array(
    'category' => $category,
    'articlesByCategory' => $articlesByCategory,
    'articles' => $articles,
    'pagination' => $articles->pagination()
  );
};

```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [June 14, 2018, 8:21am UTC](https://forum.getkirby.com/t/pagination-link-throws-error-404/10622/2 "2018-06-14T08:21:58Z")

</div>

What is in your blog.php template? Somehow it doesn’t make sense to me that you have two separate collections, $articles (with a pagination object) and $articlesByCategory (without a pagination object).

---

<div class="post-metadata">

**Author:** ![polyester](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@polyester](https://forum.getkirby.com/u/polyester)\
**Post date:** [June 14, 2018, 8:53am UTC](https://forum.getkirby.com/t/pagination-link-throws-error-404/10622/3 "2018-06-14T08:53:07Z")

</div>

In my blog.php template i have:

```
if (param('category')): // show articles by category ?>
<?php foreach($articlesByCategory as $article): ?>
...
<?php endforeach ?>

<?php else: // show articles ?>

<?php foreach($articles as $article): ?>
...
<?php endforeach ?>

<?php endif ?>

```

And then the pagination as seen above.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [June 14, 2018, 9:06am UTC](https://forum.getkirby.com/t/pagination-link-throws-error-404/10622/4 "2018-06-14T09:06:29Z")

</div>

> [@polyester](#):
>
> ‘pagination’ =\> $articles-\>pagination()

Well, yes, but your pagination object only refers to the $articles collection, I recommend you do it as explained in the docs: [https://getkirby.com/docs/cookbook/tags/#blog-controller](https://getkirby.com/docs/cookbook/tags/#blog-controller)

---

<div class="post-metadata">

**Author:** ![polyester](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@polyester](https://forum.getkirby.com/u/polyester)\
**Post date:** [June 14, 2018, 9:34am UTC](https://forum.getkirby.com/t/pagination-link-throws-error-404/10622/5 "2018-06-14T09:34:15Z")

</div>

I’ve got it. Thank you.

---

<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:27pm UTC](https://forum.getkirby.com/t/pagination-link-throws-error-404/10622/6 "2025-02-06T17:27:59Z")

</div>

Archived on February 6, 2025, 5:27pm UTC


