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

SOLVED: Adding summary of Post to SideBar


Go to End


2112 Views

Avatar
Riposte

Community Member, 10 Posts

26 April 2014 at 5:54pm

Edited: 27/04/2014 10:35am

Hi All
I would like to add the last 3 blog post summaries (or first paragraphs?) to a sidebar.
I tried this as a first step:

<% if BlogEntries %>
<% loop BlogEntries %>
<% include BlogSummary %>
<% end_loop %>
<% else %>
<h2><% _t('BlogHolder_ss.NOENTRIES', 'There are no blog entries') %></h2>
<% end_if %>

But it always returns 'There are no blog entires' which I guess indicates BlogEntries isn't populated when the home page loads.

Any ideas where I am going wrong?

SOLVED: This didn't come up in my forum search but reading the post "How to add blog tags to home page" below gave me the answer:

Needed a retrieval function in my page.php file Page_Controller class:

public function LatestBlogs($num=5) { 
return DataObject::get('BlogEntry', array('ShowInSearch'=>'1'), 'Date DESC', '', $num); 
}

Then in Page.ss

<% if LatestBlogs %>
   <% loop LatestBlogs(2) %>
   <h3>$MenuTitle</h3>
   <p>$Content.Summary()</p>
					  
<% end_loop %>

Seems to work ok.

Cheers