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, biapar, Willr, Ingo, swaiba, simon_w

DataObject::Get and hidden pages


Reply


2 Posts   1344 Views

Avatar
fostahgix

Community Member, 9 Posts

14 July 2010 at 11:39am

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

Avatar
fostahgix

Community Member, 9 Posts

14 July 2010 at 11:46am

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;
   }