Jump to:

794 Posts in 408 Topics by 304 members

Widgets

SilverStripe Forums » Widgets » Latest pages widget for children pages

Discuss SilverStripe Widgets.

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

Page: 1
Go to End
Author Topic: 1615 Views
  • DyingMuppet
    Avatar
    Community Member
    11 Posts

    Latest pages widget for children pages Link to this post

    Hi guys,

    I was wondering how I could modify the Latest pages widget from simon_w to show only the latest couple of children pages for a brief overview (in most cases only the title) of the children pages from a couple of parent pages (note: I don't want every page to have this for its own, Its more a static bar with the latest article titles.)

    TIA
    Dre

  • joshy
    Avatar
    Community Member
    57 Posts

    Re: Latest pages widget for children pages Link to this post

    (OP is referring to http://www.silverstripe.org/Latest-Pages/)

    In the widget, the controller DataObject::get currently finds 5 results. Change the '5' to '2' and you've sorted one problem. You'll also want to make sure it only grabs the articles from certain sections, so add ParentID = $this->ID or whatever you need:

    $pages = DataObject::get('SiteTree', 'ParentID = '.$this->ID, '`LastEdited` DESC', '', 5);

    For issue two - showing a brief overview - you need to edit the template. In the control the anchor tag currently shows <span>$Page.MenuTitle</span>.

    You will need to add $Page.Content or $Page.Content.Summary wherever you want it.

    Hope this helps.

    Edit: re-read what you said and adjusted accordingly

  • DyingMuppet
    Avatar
    Community Member
    11 Posts

    Re: Latest pages widget for children pages Link to this post

    Thats some very useful info, joshy. Thanks very much.

    I'll try to implement this in my site and will keep you in touch.

    Grtz, Dre

  • DyingMuppet
    Avatar
    Community Member
    11 Posts

    Re: Latest pages widget for children pages Link to this post

    A little thought:

    I guess, from the code Joshy posted that this will show only the latest couple of articles from the parent page I'm on atm.
    This is at least a part of what I want to show, maybe I can look into it myself when I have some spare time.
    My point actually was to show the same couple of parent pages with the latest children pages on a main sidebar the whole time.

    I suppose this has to be some hardcoded ID to use, or via a little bit of control on the CMS side?
    For the time being a hardcoded ID wouldn't be much of a problem.

    TIA
    Dre

  • DyingMuppet
    Avatar
    Community Member
    11 Posts

    Re: Latest pages widget for children pages Link to this post

    I have changed the LatestPages function a bit to accomplish a part of my needs.
    I can now see the children pages on the sidebar when I'm on the parent page, although when I switch to one of the children, the data on the sidebar is gone.

    this is the code I have:

       function LatestPages($amount) {
          if($amount == null) { $amount = 3; }
          $pages = DataObject::get('SiteTree', 'ParentID = '.$this->ID, '`LastEdited` DESC', ' ', $amount);
          $return = new DataObjectSet();
          foreach($pages as $page) {
             $versioned = Versioned::get_version("SiteTree", $page->ID, $page->Version);
             $author = Member::get_one("Member", "ID = " . (int)$versioned->AuthorID);
             $parent = Member::get_one('SiteTree', $page->ParentID);
             $return->push(new ArrayData(array('Page' => $versioned, 'Author' => $author, 'Parent' => $parent)));
          }
          return $return;
       }

    I'm not yet familiar with implementing a module in the CMS to select pages that should be shown in the sidebar, maybe this would be a much better and easier approach.

    Cheers, Dre

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