Hello everyone!
I can't find out on forum, how display all blog tags on home page? Any ideas?
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.
Hello everyone!
I can't find out on forum, how display all blog tags on home page? Any ideas?
In HomePage.php...
function LatestBlogs() {
return DataObject::get('BlogEntry', 'ShowInSearch=1', 'Date DESC', '', 5);
}
This shows the most recent 5 posts, from newest to oldest. Change the last parameter to change the number of posts returned.
Posts with 'Show In Search' unchecked are excluded.
In homepage.ss...
<ul>
<% control LatestBlogs %>
<li class="$LinkingMode<% if first %> first<% else_if last %> last<% end_if %>"><a href="$Link">$MenuTitle</a></li>
<% end_control %>
</ul>
The classes first & last are added to help with styleing.
Optionally, if you plan on having a lot of blog posts, add a database index to the blog date field to speed up the LatestBlogs function. Add BlogEntryDecorator.php
class BlogEntryDecorator extends DataObjectDecorator {
public function extraStatics() {
return array(
'indexes' => array(
'date' => '(Date)',
)
);
}
}
Add to _config.php
Object::add_extension('BlogEntry', 'BlogEntryDecorator');
Is there a Blog Module User Guide somewhere which describes how to do this in SS3? After some trial and random bits of information from widely distributed sources, I found that I needed to change the "control" to "loop" and then I could display $MenuTitle and $Content.Summary() with classes and formatting of my choosing.
My retrieval function in my _Controller is:
public function LatestBlogs($num=5) {
return DataObject::get('BlogEntry', array('ShowInSearch'=>'1'), 'Date DESC', '', $num);
}