Random Sticky
Plugins
On a website I needed a kind of “featured article of the day” to sit on top of all other articles. This article was to be pulled randomly from all entries of a particular weblog and was supposed to automatically change every 24 hours.
My first approach was to simply use:
{exp:weblog:entries limit="1" orderby="random" cache="yes" refresh="1440"}
While this was working in principle there were two drawbacks:
- I’m clearing all caches when new entries are posted.
- Using two weblog:entries-tags - one for the random and one for the rest - leaves me with the possibilty of one article appearing twice unless I use some extra code to exclude the randomly selected entry from the second list.
So my second approach was writing a small plugin that randomly reassigns the ‘sticky’-flag(s) in a given weblog in fixed intervals.
Usage:
Put the plugin-tag into one of your templates. Preferably into one where your sticky entry will be displayed.
{exp:randomsticky weblog="blog"}
There are four parameters.
weblog=""
Mandatory. This is the short name of the weblog where the sticky is to be randomly rotated.
duration=""
Optional. This is the duration in minutes after which new sticky flags will be set.
If left out it defaults to 1440 (24 hours).
status=""
Optional. Only entries with the specified status are candidates for a sticky.
If left out it defaults to ‘open’.
amount=""
Optional. The number of entries that are to be stickied.
If left out it defaults to 1.
Note:
This plugin requires the cache-folder in your EE system directory to be writeable by EE. A folder named ‘randomsticky’ will be created there.


Download: pi.randomsticky.zip


