[TYPO3-english] How to show a random news in list or last mode
t33k.RE.MO.VE at RE.MO.VE.prolabium.com
Tue May 5 23:23:36 CEST 2009
Taras Sajuk wrote:
> I have some news (tt_news), basically announcements of publication in the
> future. They all have a start and a end date.
> I want to show only one, but random, of the active news entries (start < now
> < end) in LIST or LAST mode of the FE-plugin.
> I have the feeling that the "listStartId" value is a good start, but how do
> I get the total number of visible news and how can I set the "listStartId"
> to a random value?
You could try somthing like this:
temp.myRandomNews = CONTENT
table = tt_news
// uid of the page where the news are stored in BE
pidInList = 444
where = deleted=0 AND hidden=0
orderBy = rand()
max = 1
Remember that if you use CONTENT then in the news template
(tt_news_v2_template.html) TEMPLATE_SINGLE_RECORDINSERT is used to
render each news.
Then if you want it to be random every time you refresh page you should try:
temp.myRandomNewsRefreshAlways = COA_INT
temp.myRandomNewsRefreshAlways.10 < temp.myRandomNews
But take care that it will be calculated every time you refresh page so
there will be performance lost.
If this news can be changed for example every one hour then its better
to use extension COA_GO (coago in TER) and try something like this:
temp.myRandomNewsRefreshOncePerHour = COA_GO
temp.myRandomNewsRefreshOncePerHour.10 < temp.myRandomNews
cache.type = afterCache_file
cache.period = 3600
cache.hash = myRandomNewsRefreshOncePerHour
The content of temp.myRandomNews is then generated only once per hour so
performance is not affected so much as when using COA_INT.
More information about the TYPO3-english