Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

How to sort pictures by name

Started by Muut Archive 12 years ago · 22 replies · 2048 views
12 years ago

I have build a little gallery template with :

{% for image in page.media.images %}
<a href="{{ image.url }}">{{ image.cropResize(100000,350).html }}</a>
{% endfor %}

But I want to sort pictures by name ... How can I do that ?

12 years ago

The images should be by default sorted by filename. The page.media.images object is an array of medium objects where the key is the filename so you could try resorting with page.media.images|sort but it should not be necessary.

12 years ago

Thanks "|sort" is really necessary to get the file in the right order. without |sort they are sorted by date.

12 years ago

same for me when is on the server, might be related with php / apache config ...
also had to add sort to get the first image right

...media.images|sort|first

12 years ago

What were the filenames you had in your folder, and what order were they displaying in?

12 years ago

01.livro-grafites-brasil.jpg
02..livro-grafites-brasil.jpg
03.livro-grafites-brasil.jpg
04.livro-grafites-brasil.jpg
05.livro-grafites-brasil.jpg
06.livro-grafites-brasil.jpg

Could not find any logic on the order. 05 was showing first ....
But this was fixed with the sort filter.

12 years ago

Yep I think my files too were by date ...

12 years ago

Kind of strange, I am unable to replicate using those filenames. Grav is just ordering by looping over the files with a PHP DirectoryIterator. I've manually sorted using a natural algorithm before returning the array of images now, so in future releases |sort should not be necessary.

Out of curiosity, do you guys also have issues with regular Grav pages not being in the expected order? Even when you use .01, .02, .03 prefixes?

12 years ago

yes , I also had it with pages, and to tell the true I also had this kind of issue sometime ago with pico CMS, but I must remind that the problem only shows off when uploaded to the remote server ( my runs with PHP 5.4.33 ) on my MAMP all looks fine.

12 years ago

Do you happen to know what kind of server you are running on your remote site (OS version, perhaps hosting provider name, PHP version, etc)?

I think I can probably force a sort to override the directory iterator for pages too, but it would be really nice if I could recreate it to ensure it's actually working.

12 years ago

I am also on siteground with with PHP 5.4.33 , forcing sort for pages did worked too

12 years ago

Could you send me a zip of your user folder containing folders that have this issue with ordering on SiteGround? Or put them on dropbox? Please send them to rhuk(a)getgrav.org

10 years ago

I am having this issue, works on my local machine but not not when I move the site to production. My question is , how do I force sort taxonomies to list by alpha? I am not using the taxonomy list plugin.

10 years ago

Most likely if it works local and not remotely, then it's a case-sensitivity thing.. This is because by default, Windows and OS X (most common user OSes) are not case-sensitive, and most servers run Linux which is.

👍 1
10 years ago

Can you be more specific? Is it the way I am I am naming my directories that contain the md file? They are all first word capitialized. Should I change to all lowercase? It was working before and it broke recently when we incorporated a category in the taxonomy. Thanks.

10 years ago

Can you delete the reply above? This is properly formatted.

My mac is not case sensitive. Do you have any other ideas? I did notice that alpha sort works one level down in the directory structure, but break at two levels down. Could this be caused by a conflict with a plugin?

TXT

   Type (Bundle):            hfs
   Name (User Visible):      Mac OS Extended (Journaled)
   Journal:                  Journal size 40960 KB at offset 0x11bec000
   Owners:                   Enabled```
10 years ago

You are saying that the sorting is working locally, but not on your remote server. So that leads me to think that it's a case sensitivity issue somehow. I would need to see the code you are using to sort your pages, along with a screenshot of the files themselves to know if that's the case.

Alternatively you can zip up your site, and make it available for me to download and test it myself (my mac is formatted with case sensitive file system for just this reason). if you go with this approach, please let me know exactly which page is having the problem.

10 years ago

that sounds great. how do I get a zip file to you?
thanks!

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1362 9 years ago
Archive · by Muut Archive, 9 years ago
2 939 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2959 9 years ago
Archive · by Muut Archive, 9 years ago
3 1123 9 years ago