21491 Posts in 5783 Topics by 2621 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 752 Views |
-
show article with an option checked

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,
cbartgu,
-
Re: show article with an option checked

18 June 2009 at 2:47am
The easiest way would be to create a custom method that will return a random article.
Example:// 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 %>
| 752 Views | ||
|
Page:
1
|
Go to Top |


