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.

Blog Module /

Discuss the Blog Module.

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

SOLVED: Adding summary of Post to SideBar

Go to End



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

<% if LatestBlogs %>
   <% loop LatestBlogs(2) %>
<% end_loop %>

Seems to work ok.