Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Figured out how to get children under a certain page.

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: 3500 Views
  • a-tech
    Avatar
    Community Member
    39 Posts

    Figured out how to get children under a certain page. Link to this post

    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;

  • a-tech
    Avatar
    Community Member
    39 Posts

    Re: Figured out how to get children under a certain page. Link to this post

    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.

  • Sam
    Avatar
    Administrator
    679 Posts

    Re: Figured out how to get children under a certain page. Link to this post

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

    3500 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.