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

Get entries of a specific blogHolder in SS3


Go to End


3 Posts   2110 Views

Avatar
sajok

Community Member, 82 Posts

12 April 2013 at 12:47pm

Edited: 12/04/2013 12:50pm

Hello,

I'm trying to get the latest blog entries from a specific blogholder, to be shown inside another blogholder using this code:

class BlogHolderDecorator extends DataExtension { 
   
   public function latestNews($max) {
   		$holder = DataList::create('BlogHolder')->filter('URLSegment', 'blog');
         return DataList::create('BlogEntry')->filter('ParentID', $holderID)->limit($max);
	} 
}

in BlogHolder.ss I have:

<% loop latestNews('5') %>
	<li>
	<h4>$Title</h4>
	<p>$Content.FirstParagraph(html)</p>
	</li>
<% end_loop%>

This doesn't work yet.. any idea what I'm missing here?

Thanks

Avatar
Willr

Forum Moderator, 5523 Posts

12 April 2013 at 8:25pm

Your PHP has a few little typo's. It should look like

$holder = DataList::create('BlogHolder')->filter('URLSegment', 'blog')->first();

return DataList::create('BlogEntry')->filter('ParentID', $holder->ID)->limit($max);

Avatar
sajok

Community Member, 82 Posts

13 April 2013 at 12:54am

Thank you Willr, it works now.