I’m fetching my projects to give a list populated items with projects corresponding to the category.
<?php foreach ($site->find('projets')->children()->filterBy('category', $item->action())->images() as $image) : ?>
gives :
Project 1
image 1 (filename is a.jpg)
image 2 (filename is b.jpg)
image 3 (filename is c.jpg)
Project 2
image 1 (filename is 1.jpg)
image 2 (filename is 3.jpg)
image 3 (filename is 4.jpg)
So right now, these files are displayed correctly by the default sort method, in the correct project order starting with 1 then all the files in it, and then project 2 with all images in it.
But I would like to organise the images in them depending on the defined sorting in my panel. ->sortBy("sort")is usually what I would go with.
<?php foreach ($site->find('projets')->children()->filterBy('category', $item->action())->images()->sortBy("sort") as $image) : ?>
It gives a mixing of Project 1’s images with images from project 2 . (it seems that the order of the images are the same as in the panel order, though).
Project 1
image 1 (filename is a.jpg)
Project 2
image 1 (filename is 1.jpg)
Project 1
image 3 (filename is c.jpg)
Project 2
image 2 (filename is 2.jpg)
Project 1
image 2 (filename is b.jpg)
Project 2
image 3 (filename is 3.jpg)
I would like to keep the project order, but just display the images in the panel order.
I’m having all of them in a loop for a caroussel.
The logic is sliding all the images of the first project, and as soon as you reach the end the of list, the second project follows.
It’s working nicely right know as the slider is able to update some divs depending on the slide you are seeing.
It works for the projects, but it ignores the way the images are sorted inside the corresponding project.
So I have some images in these projects that I would also like to sort by the way they are organised in the panel. $projects->images()->sortBy('sort');
images()->sortBy('parent', 'sort'); sorts the image correctly, but ignore the way the parents have also been sorted in the panel.
$projects = $site->find('projets')->children()->filterBy('category', $item->action())->sortBy('num');
foreach ($projects as $project) {
foreach ($project->images()->sortBy('sort') as $image) {
// do stuff with the image
}
}