# Sorting from different subpages

**URL:** <https://forum.getkirby.com/t/sorting-from-different-subpages/11165>\
**Category:** Questions\
**Tags:** v2\
**Created:** [September 5, 2018, 1:24pm UTC](https://forum.getkirby.com/t/sorting-from-different-subpages/11165 "2018-09-05T13:24:07Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oziris](https://avatars.discourse-cdn.com/v4/letter/o/df788c/32.png) [@Oziris](https://forum.getkirby.com/u/Oziris)\
**Post date:** [September 5, 2018, 1:24pm UTC](https://forum.getkirby.com/t/sorting-from-different-subpages/11165/1 "2018-09-05T13:24:07Z")

</div>

Hello everyone

I’m currently sorting pages from two differents subfolder (Projects and News). I would like to be able to sort them manually to render them into the frontpage.

So my actual code is :

```
<?php foreach($pages->children()->visible()->sortBy('modified', 'asc')->flip() as $product): ?>

...

<php endforeach ?>

```

I know it is not the right way to do it because this code takes in account the modified pages.

For example, I would like to get the third « News » page comes to first position, and the second page from projects comes to the last…This could be possible if I grouped my « projects » and « news » pages into one single folder, but I would like to avoid that, and to know if an other way was possible.

---

<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:** [September 5, 2018, 1:38pm UTC](https://forum.getkirby.com/t/sorting-from-different-subpages/11165/2 "2018-09-05T13:38:18Z")

</div>

I don’t really understand your requirement. Manually for me means, that you have a select field or whatever, where you select the pages you want to display and there order. Then. you renders these manually selected pages in the. page.

What is the underlying pattern for “3rd news page” and then “second page from projects comes last”?

---

<div class="post-metadata">

**Author:** ![Oziris](https://avatars.discourse-cdn.com/v4/letter/o/df788c/32.png) [@Oziris](https://forum.getkirby.com/u/Oziris)\
**Post date:** [September 5, 2018, 1:47pm UTC](https://forum.getkirby.com/t/sorting-from-different-subpages/11165/3 "2018-09-05T13:47:30Z")

</div>

Sorry, this is quite difficult to explain, so this is an architecture example :

Projects :

- A
- B
- C
- D

News :

- 1
- 2
- 3
- 4

The result I am expected for in the frontend is, for example :

Teaser:

- 1
- 2
- A
- 3
- B
- 4
- C
- D

Because this order would be “manually” or “intentionnaly” wanted.

---

<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:** [September 5, 2018, 1:59pm UTC](https://forum.getkirby.com/t/sorting-from-different-subpages/11165/4 "2018-09-05T13:59:04Z")

</div>

But that sort order is only an example, so you could also have a different order? What pattern is there that defines the desired order? What if there are more then 4 post in each/any of the folders?

If you. don’t want to pick them manually like I suggested, you need some pattern to base your algorithm on.

---

<div class="post-metadata">

**Author:** ![Oziris](https://avatars.discourse-cdn.com/v4/letter/o/df788c/32.png) [@Oziris](https://forum.getkirby.com/u/Oziris)\
**Post date:** [September 5, 2018, 2:05pm UTC](https://forum.getkirby.com/t/sorting-from-different-subpages/11165/5 "2018-09-05T14:05:26Z")

</div>

Right, this is only an example, the user would like to change this order as he wants to. In the homepage, the teaser could change the order between “projects” and “news” pages.  
What do you mean by “pattern” ?

---

<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:** [September 5, 2018, 2:12pm UTC](https://forum.getkirby.com/t/sorting-from-different-subpages/11165/6 "2018-09-05T14:12:16Z")

</div>

Well, you want to display pages from two different subfolders manually. But you want to do your manual sorting with code. But with code, you can only do things that have some inherent logic, a pattern, like always take two form the first list, then continue with 1 from the next list, then again two from the first list etc. The opposite would be to do something randomly with code.

But if you want to do something manually, you can’t do it with a programming algorithm. Why don’t you use a plugin like [Kirby relationship](https://github.com/olach/kirby-relationship) where the users can select and order the pages they want to show on the start page?

---

<div class="post-metadata">

**Author:** ![Oziris](https://avatars.discourse-cdn.com/v4/letter/o/df788c/32.png) [@Oziris](https://forum.getkirby.com/u/Oziris)\
**Post date:** [September 5, 2018, 2:38pm UTC](https://forum.getkirby.com/t/sorting-from-different-subpages/11165/7 "2018-09-05T14:38:11Z")

</div>

Thanks for sharing this plugin, let me some time to implement it and keep you informed of the result

---

<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:** [September 5, 2018, 2:39pm UTC](https://forum.getkirby.com/t/sorting-from-different-subpages/11165/8 "2018-09-05T14:39:30Z")

</div>

Use a controller to select options from. both parents: [https://github.com/olach/kirby-relationship#controller](https://github.com/olach/kirby-relationship#controller)

---

<div class="post-metadata">

**Author:** ![Oziris](https://avatars.discourse-cdn.com/v4/letter/o/df788c/32.png) [@Oziris](https://forum.getkirby.com/u/Oziris)\
**Post date:** [September 6, 2018, 8:04am UTC](https://forum.getkirby.com/t/sorting-from-different-subpages/11165/9 "2018-09-06T08:04:05Z")

</div>

Ok, I tried this plugin, but it didn’t really suited me because the plugin is working with a selecting principle, and I don’t need this. I am more interested by this plugin : [https://github.com/lukaskleinschmidt/kirby-sortable](https://github.com/lukaskleinschmidt/kirby-sortable) because it allows to directly change the order of the subpages. But now, I realize that we can’t make multiple parents, it only find the siblings or the selected subpages from one level.

So, my new idea is to add a `date` field to every “news” and “projects” subpages. This way I could create a collection and order them arbitrary from this date value (which is not far from what I am looking for). Do you have some advices about doing that ?

EDIT : this way, I could get what I was looking for :

```
 <?php $collection = $pages->children()->visible()->sortBy('date', 'desc');
    foreach($collection as $product): ?>
...
<?php endforeach ?>
```

---

<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:** [September 6, 2018, 9:18am UTC](https://forum.getkirby.com/t/sorting-from-different-subpages/11165/10 "2018-09-06T09:18:58Z")

</div>

Glad you sorted it out, didn’t know you wanted to sort by date, that’s why I asked for a pattern.

---

<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:26pm UTC](https://forum.getkirby.com/t/sorting-from-different-subpages/11165/11 "2025-02-06T17:26:19Z")

</div>

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


