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

get_one except only from child pages?


2 Posts   2695 Views


6 December 2008 at 4:32pm Community Member, 19 Posts

I am trying to do a pretty complex "news" feature for a client (almost wondering if it would be better to do a customized blog module?)

The idea is that there are several pages for several different buildings, each that have different news items. So I did the NewsHolder / News style page from the tutorials, only the get_one function seems to pull in news from any NewsHolder page as when I added more than one NewsHolder it stopped working.

Instead I tried to do a <% control Children %> / <% if ClassName = NewsHolder %> however it will list every news item rather than the top 5 for example.

Finally is there any way to get this working and also create a "sticky" news item?


8 December 2008 at 2:18pm Community Member, 19 Posts

Just in case someone has the same problem this is the code I used to make it work

   function LatestNews($num=5) {
      $childNews = DataObject::get_one("NewsHolder","ParentID = $this->ID", null, 1);
      return ($childNews) ? DataObject::get("News", "ParentID = $childNews->ID", "Date DESC", "", $num) : false;