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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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