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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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

DataObject::Get and hidden pages


Go to End


2 Posts   1699 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;
}