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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Blog Module /

Discuss the Blog Module.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

How display all blog tags on home page


Go to End


3 Posts   2770 Views

Avatar
neografik

Community Member, 7 Posts

10 January 2012 at 8:08am

Hello everyone!

I can't find out on forum, how display all blog tags on home page? Any ideas?

Avatar
inCharge

Community Member, 102 Posts

28 March 2012 at 12:25am

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');

Avatar
PaulO2

Community Member, 2 Posts

23 January 2014 at 2:22am

Edited: 28/01/2014 7:38pm

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