1770 Posts in 495 Topics by 531 members
Blog Module
SilverStripe Forums » Blog Module » Returning a Child Blog Page's Posts
Discuss the Blog Module.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 438 Views |
-
Returning a Child Blog Page's 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?
-
Re: Returning a Child Blog Page's Posts

25 January 2013 at 6:03am Last edited: 25 January 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 %>.
| 438 Views | ||
|
Page:
1
|
Go to Top |


