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

Pulling latest 3 blog posts and paste on main page


Go to End


3 Posts   1382 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, 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.

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