# Sorty by date and time .. pagination?

**URL:** <https://forum.getkirby.com/t/sorty-by-date-and-time-pagination/6920>\
**Category:** Questions\
**Tags:** v2\
**Created:** [March 11, 2017, 6:07pm UTC](https://forum.getkirby.com/t/sorty-by-date-and-time-pagination/6920 "2017-03-11T18:07:56Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![OhDerAlex](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/ohderalex/32/3838_2.png) [@OhDerAlex](https://forum.getkirby.com/u/OhDerAlex)\
**Post date:** [March 11, 2017, 6:07pm UTC](https://forum.getkirby.com/t/sorty-by-date-and-time-pagination/6920/1 "2017-03-11T18:07:57Z")

</div>

Hi.  
I’m sorting my articles with date AND time. Because I’m sure to write more than one article at one day.

@article.yml  
`date` and `time`

@blog.yml  
`pages: sort: date asc time asc`

@listing.php  
`$limit = c::get('pagination-blog', 5); $articles = page('blog')->children()->visible()->flip()->paginate($limit); $pagination = $articles->pagination();`

and

`<?php foreach($articles->sortBy('date', 'desc', 'time', 'desc') as $article): ?>`

Without pagination he sorts it right. With this pagination he’s not sorting all articles.

---

<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:** [March 11, 2017, 6:22pm UTC](https://forum.getkirby.com/t/sorty-by-date-and-time-pagination/6920/2 "2017-03-11T18:22:59Z")

</div>

The sorting should be defined in the controller/beginning of template, not in the foreach loop.

```auto
$limit = c::get('pagination-blog', 5);
$articles = page('blog')->children()->visible()->flip()->paginate($limit)->sortBy('date', 'desc', 'time', 'desc');
$pagination = $articles->pagination();

```

---

<div class="post-metadata">

**Author:** ![OhDerAlex](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/ohderalex/32/3838_2.png) [@OhDerAlex](https://forum.getkirby.com/u/OhDerAlex)\
**Post date:** [March 11, 2017, 6:31pm UTC](https://forum.getkirby.com/t/sorty-by-date-and-time-pagination/6920/3 "2017-03-11T18:31:22Z")

</div>

This code in blog.php?  
If I do this I become an error `This page is currently offline due to an unexpected error`

@listing.php it’s not inside the loop

---

<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:** [March 11, 2017, 6:43pm UTC](https://forum.getkirby.com/t/sorty-by-date-and-time-pagination/6920/4 "2017-03-11T18:43:49Z")

</div>

Sorry, I made a mistake:

```auto
$limit = c::get('pagination-blog', 5);
$articles = page('blog')->children()->visible()->sortBy('date', 'desc', 'time', 'desc')->flip()->paginate($limit);
$pagination = $articles->pagination();
foreach($articles as $article) {
  // your code
}

```

Please turn on debugging in your config.php

```auto
c::set('debug', true);

```

to be able to see the errors.

---

<div class="post-metadata">

**Author:** ![OhDerAlex](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/ohderalex/32/3838_2.png) [@OhDerAlex](https://forum.getkirby.com/u/OhDerAlex)\
**Post date:** [March 11, 2017, 6:48pm UTC](https://forum.getkirby.com/t/sorty-by-date-and-time-pagination/6920/5 "2017-03-11T18:48:05Z")

</div>

Yay this works. Thank you (again). But whats about

`pages: template: article num: date sort: date asc time asc`

@blog.yml ? Why I need `->sortBy('date', 'desc', 'time', 'desc')` to sort it?

---

<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:** [March 11, 2017, 6:49pm UTC](https://forum.getkirby.com/t/sorty-by-date-and-time-pagination/6920/6 "2017-03-11T18:49:27Z")

</div>

Because the sort settings in the blueprint only apply to the sort order of the subpages in the Panel, it has no effect whatsoever on the frontend.

---

<div class="post-metadata">

**Author:** ![OhDerAlex](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/ohderalex/32/3838_2.png) [@OhDerAlex](https://forum.getkirby.com/u/OhDerAlex)\
**Post date:** [March 11, 2017, 6:50pm UTC](https://forum.getkirby.com/t/sorty-by-date-and-time-pagination/6920/7 "2017-03-11T18:50:07Z")

</div>

aaah … ok 🙂 understood

---

<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, 4:50pm UTC](https://forum.getkirby.com/t/sorty-by-date-and-time-pagination/6920/8 "2025-02-06T16:50:28Z")

</div>


