Jump to:

23355 Posts in 17838 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » DataObject::Get and hidden pages

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: 1293 Views
  • fostahgix
    Avatar
    Community Member
    9 Posts

    DataObject::Get and hidden pages Link to this post

    Hello everyone,

    I am trying to do get the latest posts that are NOT hidden(Show in Menus? is unchecked). Right now the get() I do below returns all published pages. I just need to omit pages that are hidden from the result.

    Below is my controller code and template code:

    Page.php Controller Code:

    public function LatestEvents($num=3) {
          $events = DataObject::get_one("EventListing");
          return ($events) ? DataObject::get("EventPage", "ParentID = $events->ID", "Date DESC", "", $num) : false;
    }

    Template Code/Loop:

    <% control LatestEvents(4) %>
                      <li><% if MultipleDates %>$MultipleDates<% else %>$Date.Format(n.j.y)<% end_if %><p><a href="$Link" title="Read more on &quot;{$Event}&quot;">$Event</a></p></li>
    <% end_control %>

  • fostahgix
    Avatar
    Community Member
    9 Posts

    Re: DataObject::Get and hidden pages Link to this post

    Found out the solution!

    Adding to the where 'AND ShowInMenus = 1' fixed it!

       public function LatestEvents($num=3) {
          $events = DataObject::get_one("EventListing");
          return ($events) ? DataObject::get("EventPage", "ParentID = $events->ID AND ShowInMenus = 1", "Date DESC", "", $num) : false;
       }

    1293 Views
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.