I'm learning about SS by creating a Latest Blog Posts widget. I've managed to create a function that outputs the posts and filters them by category (I'm using the blog and blogcategories modules).
What I'd like to be able to do now is output the category name in my template, but I can't figure out how. This is the function that gets the blog posts:
public function getLatestPosts()
{
$limit = $this->NumberToShow;
return DataList::create('BlogEntry')
->limit($limit)
->sort(array('Date' => 'DESC'))
->leftJoin('BlogEntry_BlogCategories', '"BlogEntry_BlogCategories"."BlogEntryID" = "BlogEntry"."ID"', null)
->leftJoin('BlogCategory', '"BlogCategory"."ID" = "BlogEntry_BlogCategories"."BlogCategoryID"', null)
->where('BlogCategoryID = ' . $this->BlogCategory);
}
Presumably the DataList contains all the data, but how to 'get it out' is eluding me.
In my template I have my control, where I'm able to get the title of the blog post, the date, content and so on:
<% control LatestPosts %>
$Date.Long
$Title
$Content.FirstParagraph()
<% end_control %>
Apologies if this is SS 101, I'm just a poor lowly frontend designer ;)