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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Blog Module /

Discuss the Blog Module.

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

Returning a Child Blog Page's Posts


Go to End


2 Posts   2286 Views

Avatar
reececropley

Community Member, 11 Posts

10 January 2013 at 12:37am

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?

Avatar
copernican

Community Member, 189 Posts

25 January 2013 at 6:03am

Edited: 25/01/2013 6:05am

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