Sorting from different subpages

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.

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”?

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.

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.

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” ?

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 where the users can select and order the pages they want to show on the start page?

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

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

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 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 ?>

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