17452 Posts in 4473 Topics by 1971 members
|Go to End|
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;
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.
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'");
|Go to Top|