Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

show article with an option checked

Go to End

2 Posts   1180 Views


Community Member, 12 Posts

17 June 2009 at 11:12pm

Does anyone know how to show an article which has a boolen option ticked, so if you had to pick a random article that it about a certain subject to show on the front page.

I wanted to use the <% control %> method but cannot find a tutorial on how to do it,



Community Member, 904 Posts

18 June 2009 at 2:47am

The easiest way would be to create a custom method that will return a random article.

// put this in your Page_Controller
public function RandomArticle(){
	return DataObject::get_one('ArticlePage', 'Option = 1', true, 'RAND()');

Where 'ArticlePage' is the name of your Article Page Class and 'Option = 1' would be the WHERE statement.
Then in the Template you could write:

<% control RandomArticle %>
... access members of the ArticlePage here ...
<% end_control %>