Thursday, June 18, 2009

How to change Plone's default folder listing sort order

Note: you may also want to look at this article, which show how to add new content on the top of a folder instead of at the bottom.

The easy, all-Plone way to change Plone's folder sort order is to create a Collection (or Smart Folder, or Topic) which you can configure through the web to display items from wherever you please, in whatever order you please. I think you should consider using a Collection first. For example, look how the "News" folder is set up in in a fresh Plone install. It contains a Collection which is used as the default view for the folder.

See the documentation on using Collections.

And now, the entering-a-world-of-pain way:

The folder_listing and folder_contents views use the script getFolderContents (in CMFPlone) to get brains objects.

If you want to modify the default order in which items are listed in your site, you can customize this script by adding these lines:

# Modification to alter sort order
contentFilter['sort_on'] = "modified"
contentFilter['sort_order'] = "descending"


If you wanted a different sort order for different folders, you could place the script in the folder itself. Acquisition should take care of that. (Haven't tried this myself yet.)

I have tested this on Plone 2.5, but it should work equally well on Plone 3.2.2, as the getFolderContents script is still present there.

Note that this will disable the feauture that allows you to sort the folder by hand!

No comments: