Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » get_one except only from child pages?

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

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

Page: 1
Go to End
Author Topic: 2626 Views
  • 3pointross
    Avatar
    Community Member
    18 Posts

    get_one except only from child pages? Link to this post

    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?

  • 3pointross
    Avatar
    Community Member
    18 Posts

    Re: get_one except only from child pages? Link to this post

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

    2626 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.