Jump to:

23459 Posts in 18906 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » show article with an option checked

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

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

Page: 1
Go to End
Author Topic: 885 Views
  • cbartgu
    Community Member
    12 Posts

    show article with an option checked Link to this post

    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,


  • banal
    Community Member
    901 Posts

    Re: show article with an option checked Link to this post

    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 %>

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.