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.


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

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

Figured out how to get children under a certain page.


3 Posts   3607 Views


20 March 2007 at 11:17am Community Member, 39 Posts

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;


20 March 2007 at 11:18am Community Member, 39 Posts

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.


20 March 2007 at 4:07pm Administrator, 679 Posts

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();