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
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
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.
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
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
I use:
function LatestBlogPosts($num=5) {
$blogs = DataObject::get_one("BlogHolder");
return ($blogs) ? DataObject::get("BlogEntry", "ParentID = $blogs->ID", "Date DESC", "", $num) : false;
}