Changing number of displayed news/events in Plone portlets

Find out which version of Plone you are running. Versions prior to 2.5 keep their portlet code in Zope Page Templates and can be modified easily. Plone 2.5 uses a new programming method called Views that complicates things. Versions after the 2.5.x series are not covered in this guide since they haven’t been released yet, but working with these versions will likely be the same as Plone 2.5.

Versions prior to 2.5

Go into the ZMI and navigate to /portal_skins/custom. If you already have a customized portlet_events or portlet_news, change the one you find. Otherwise, we’ll need to begin customizing a fresh copy. Go to /portal_skins/plone_portlets. Select the appropriate portlet you want to change (either portlet_events or portlet_news) and customize it.

Look for a line near the top of the file beginning with tal:define="results. This TAL define statement goes on for several more lines. Look for the end of it, which has an expression looking like: [:5]. The number after the colon controls the number of events to display, and you can change it to whatever you like.

Version 2.5 and later

Because Plone 2.5 uses Views, the code that does the searching for news or events is part of the Zope server itself. You can modify this file directly if you only have one Plone site and don’t think you’ll be changing it frequently. However, this is not the best method, just the simplest.

Directly modifying Zope

Note: this will affect all Plone sites on your server. The code is found at: instance_home/Products/CMFPlone/browser/portlets/events.py (or news.py) in the root of your Zope install directory. Look for the code that specifies sort_limit, and change it to the number of items you want to show. Then look for a line that ends with [:5] and change the number in brackets also to the number of desired items. Save the file and restart your Zope server.

Modifying the ZPT

If you have more than one Plone site, and want to change the number of events on one site without affecting the others, this method is best. By borrowing some code from the old Plone version, we can make the needed changes. Customize /portal_skins/plone_portlets/portlet_events (or portlet_news) if you don’t have a customized copy already.

Look for the first tal:define tag and remove it (all 4 lines, or 3 lines for the events portlet). Now replace it with this code:
tal:define="results python:here.portal_catalog.searchResults(portal_type='Event', end={'query': DateTime(), 'range': 'min'}, sort_on='start', sort_limit=5, review_state='published')[:5];"

(If you’re changing the news portlet, be sure to set portal_type='News Item' and remove the end= part.)

Change both the number after sort_limit= and the number in brackets at the end to be the number of items you want to display.

If you changed the events page, now you need to replace all occurrences of events_link with string:/events, and replace prev_events_link with string:/events/previous. (These are the default names. If you changed the names of the Events or Previous Events pages, you’ll need to use their new URLs here.)

If you changed the news page, replace all occurrences of prev_events_link with string:/news. (Again, this is the default name. If you changed it, use the correct URL for the News page.)

Customizing the portlets in other ways

You can change sort order, sort criteria, and other things by altering the parameters to the searchResults function that we used. See the ZCatalog help page for more information.