[TYPO3-english] How to show a random news in list or last mode

Krystian Szymukowicz 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
temp.myRandomNews {
	 table = tt_news
	 select {
		// 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
temp.myRandomNewsRefreshOncePerHour {
   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.

--
grtz
Krystian Szymukowicz


More information about the TYPO3-english mailing list