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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Blog Module /

Discuss the Blog Module.

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

Pulling latest 3 blog posts and paste on main page

Go to End

3 Posts   1110 Views


Community Member, 5 Posts

7 December 2010 at 11:18am

Hi there,

I was wondering if it's possible, some how code wise to list the last 2-3 blog post titles on the main page, with a link to the full blog. Basically, it's acting like news tool.



Forum Moderator, 5523 Posts

7 December 2010 at 12:53pm

Tutorial 2 explains what you need to do to get LatestNews working but instead of using the 'ArticlePage' type you want to look at your 'BlogEntry' types.


function LatestNews($num=5) {
  return DataObject::get("BlogEntry", "", "Date DESC", "", $num);

Then in your template use

<% control LatestNews(3) %>
<a href="$Link">$MenuTitle</a>
<% end_control %>

The tutorial has a bit more context / information.


Forum Moderator, 435 Posts

7 December 2010 at 9:05pm

I use:

function LatestBlogPosts($num=5) {
 		$blogs = DataObject::get_one("BlogHolder");
  		return ($blogs) ? DataObject::get("BlogEntry", "ParentID = $blogs->ID", "Date DESC", "", $num) : false;