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, biapar, Willr, Ingo, swaiba, simon_w

Pulling latest 3 blog posts and paste on main page


Reply


3 Posts   786 Views

Avatar
infused

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.

Thanks

Avatar
Willr

Forum Moderator, 5513 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.

mysite/code/HomePage.php

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. http://doc.silverstripe.org/tutorial:2-extending-a-basic-site#showing_the_latest_news_on_the_homepage

Avatar
biapar

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;
   }