NewsItems archive using SmartFolders and expirationdate

by Harald Friessnegger last modified Dec 30, 2008 03:02 PM
This howto shows a way to separate current news from archived ones using expiration date and smartfolders by making the catalog return expired items too.

Goal

Similar to Events and Events/PastEvents you may want to publish old news in an archive as well.

Past Events contains all Events that started at lease one minute ago. The news archive will contain all news having defined an exiration date that dates back to the past.

Caution:

The methods described here changes the behaviour of a default plone site: Expired content is now available for anonymous users.

If you are using expiration date to hide conent form anonymous users elsewhere on your site you could implement the archive using a new workflow state 'archived' and check for this state in the SmartFolder.

Setup

create the smart folders anywhere you want them and use the following criteria:

criteria for current news:

  • type: NewsItem
  • expiration-date: relative: (morethan, now, infuture)
  • location: navigate to the folder you store the news, or collect them from the whole site
  • sort-on: creationdate

criteria for archive:

  • type: NewsItem
  • expiration-date: relative: (lessthan, now, ago)
  • location: navigate to the folder you store the news, or collect them from the whole site
  • sort-on: creationdate

If you test this setup as manager everything will be fine. If you try the smartfolders in another browser as anyonymous user wou'll find out that archive and current both show exactly the same news items.

This is because portal_catalog exculdes expired items from the search results unless you have the proper permission.

You need to grand "Access inactive portal content" to the roles you want to make the smartfolder return the expected result. Normally this permission is only set for 'Owner', we set it on 'Anonymous' (this will affect all other roles too) You need to set the permission on portal level (doing this on the smartfolders does not work). Remember that this may change behaviour you rely on elsewhere and so break other parts of your site!

Thanks to:
elvix, shapr and sashav for the helpful discussion on irc