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.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

Figured out how to get children under a certain page.


Go to End


3 Posts   7119 Views

Avatar
a-tech

Community Member, 39 Posts

20 March 2007 at 11:17am

I was trying to figure out how to beat the 'get_one($obj)' method so that I could get a certain object type from under a specific page name.

For example, i have 2 blocks of news (same object of ArticlePage) which are 'current' and 'archive' ' and i want to list the two different lots

In the end I figured it out, by hovering over the page number in the CMS (in this eg it was 21), I can see the ID, and then i use this to get the DataObject Parent.

$news = DataObject::get_by_id("ArticleHolder", 21);

and follow it with below for the items

return ($news) ? DataObject::get("ArticlePage", "ParentID = $news->ID", "Date DESC", "", 5) : false;

Avatar
a-tech

Community Member, 39 Posts

20 March 2007 at 11:18am

Oh, if any of the SS team know of an easier way to get the ID of a page name via code (rather than manually finding it myself), I would appreciate it.

Avatar
Sam

Administrator, 690 Posts

20 March 2007 at 4:07pm

You can do it in a template by nesting 2 control blocks:

<% control Page(my-url) %>
<% control Children %>
...

Or in code by calling similar methods

$otherPage = DataObject::get_one("SiteTree", "URLSegment = 'my-url'");
return $otherPage->Children();