1770 Posts in 495 Topics by 531 members
Blog Module
SilverStripe Forums » Blog Module » Pulling latest 3 blog posts and paste on main page
Discuss the Blog Module.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 521 Views |
-
Pulling latest 3 blog posts and paste on main page

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
-
Re: Pulling latest 3 blog posts and paste on main page

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
-
Re: Pulling latest 3 blog posts and paste on main page

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;
}
| 521 Views | ||
|
Page:
1
|
Go to Top |


