Jump to:

1851 Posts in 1606 Topics by 561 members

Blog Module

SilverStripe Forums » Blog Module » Returning a Child Blog Page's Posts

Discuss the Blog Module.

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

Page: 1
Go to End
Author Topic: 807 Views
  • reececropley
    Avatar
    Community Member
    11 Posts

    Returning a Child Blog Page's Posts Link to this post

    Hello I have a site with multiple blogs on it.

    The site is for a sports club and each sport has its own page (page.ss). These pages have children on Calenders, Blogs and other pages.

    On the sport page I would like to display a feed of their specific blog.

    I have managed to display a widget for there specific widget using the following code.

    Page.php

    public function GetChildren($Limit = 1){

          $Children = $this->Children();

          return $Children->limit($Limit, 0);

       }
       
       public function CalendarWidget() {
          return Calendar::get()->first()->CalendarWidget();
       }

    Page.ss

    <% control Children %>

       <% control $GetChildren %>
          $CalendarWidget
    <% end_control %>
       

    <% end_control %>

    I was wondering if there is a way of displaying the blog feed for just the children.

    I was thinking something along the lines of the following: (error code btw)

    Page.php

    public function LatestBlogEntry($num=4) {
          $Children = $this->Children();
          $blogpost = $Children::get_one("BlogHolder");
          return ($blogpost) ? DataObject::get("BlogEntry", "", "Date DESC", "", $num) : false;
       }

    Has anyone done something similar before?

  • IOTI
    Avatar
    Community Member
    189 Posts

    Re: Returning a Child Blog Page's Posts Link to this post

    In this situation I wouldn't rely on using the children to get the blog holder. What if there are two blog holders? what if there are none? What i usually do in this situation is add a TreeDropdownField that allows a CMS user to pick the blog holder they want to use.

    <?php

    class Page extends SiteTree {

    public static $has_one=array(
    'BlogHolder'=>'SiteTree'
    );

    public function getCMSFields(){

    $fields->addFieldToTab('Root.Content.Main', new TreeDropdownField('BlogHolderID','Select a Blog Holder', 'SiteTree'));
    }

    public function getBlogEntries($limit=4){
    if($this->BlogHolderID){
    if($blogHolder = DataObject::get_one('BlogHolder', $this->BlogHolderID)){
    return $blogHolder->Entries($limit);
    }else {
    return false;
    }
    }else {
    return false;
    }
    }

    }

    then on your template use <% control BlogEntries %>.

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