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've moved the forum!

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.

Blog Module /

Discuss the Blog Module.

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

Q: Multiple blogs with latest post on HomePage


Go to End


17 Posts   9350 Views

Avatar
OnebyOne

Community Member, 54 Posts

4 May 2009 at 9:19pm

I'll use blog module for news site. Since we don't have categories like in forum module. I had to create a Blog Holder for each section.

Now, i would like to display from each section latest blog posts on Home Page.

HomePage
|- blog holder 1 (section 1 of news)
|- blog holder 2 (section 2 of news)
....
|- blog holder n (section n of news)

Applying http://www.silverstripe.org/blog-module-forum/show/254124#post254124 or http://www.silverstripe.org/blog-module-forum/show/258365#post258365 i'll get only entries from [blog holder 1].

Any idea to do this ?

THX

Avatar
Nivanka

Community Member, 400 Posts

11 May 2009 at 1:00am

this gave me the idea to create a widget to make this possible, I will start on it soon! would be nice to have such a thing ;)

Avatar
Nivanka

Community Member, 400 Posts

7 June 2009 at 4:12pm

As i wrote about a widget, I create a new widget to achieve this. Welcome to use it.

Attached Files
Avatar
Web Designer Perth

Community Member, 49 Posts

12 June 2009 at 6:52pm

@Nivanka - I DL'd your widget. Works perfectly.

I used the blog module as just part of a bigger site - how can I get the latest post on the main 'static' homepage?

Any help much appreciated as I'm a complete noob.

Avatar
Web Designer Perth

Community Member, 49 Posts

15 June 2009 at 11:21am

I would also like to know if there is a way, when showing multiple latest entries in the widget, to have the newest entry at the top of the list; oldest at the bottom. Currently it's the other way round and I can't seem to find any code governing the order.

Avatar
George

Community Member, 41 Posts

17 June 2009 at 7:54am

Edited: 17/06/2009 7:55am

For managing latest post of more blog holders you have to create for each holder a function like describe and extend it:

...
$news = DataObject::get_one('BlogHolder', "Title = '<name of blogholder>'")
...

http://silverstripe.org/blog-module-forum/show/261584?start=0#post261590

Avatar
Web Designer Perth

Community Member, 49 Posts

3 July 2009 at 1:16pm

Edited: 05/07/2009 4:02pm

Ok, I figured out how to swap the order of entries in the widget (newest top, oldest bottom), but despite setting it to show the 6 latest entries in the cms, all entries appear in the widget ie. more than 6.

Can anyone assist?

Here is the code:

<?php

// LatestBlogPost Widget 0.0.1 for the SilverStripe Blog Module
// 07.06.2009
// By nivanka@whynotonline.com
// Save this and LatestBlogPost.ss to widget_latestblogpost/ and run "db/build".

class LatestBlogPost extends Widget{

	static $title = "Latest News";
	static $cmsTitle = "Latest News";
	static $description = "With this plugin you can show up the latest blog post from any blog set up on your website.";

	static $db = array(
		"Blog" => "Int",
		"NumberOfPosts" => "Int",
	);


	//get the wanted data from the user
	function getCMSFields(){
		
		$blogs = DataObject::get('BlogHolder');
		$blogsDD = array();
		foreach($blogs as $blog)		
			$blogsDD[$blog->ID] = $blog->Title;

		return new FieldSet(
			new DropdownField("Blog", "Select a Blog", $blogsDD, $this->Blog ),
			new NumericField("NumberOfPosts", "Number of Posts")	
		);

	}

	//get the blog posts as the parameters provided
	function blogPosts(){
		$posts = DataObject::get('BlogEntry', 'ParentID = ' . $this->Blog, 'Date DESC', $this->numberOfPosts);
		return $posts;
	}

}

?>

Avatar
Nivanka

Community Member, 400 Posts

5 July 2009 at 9:58pm

so do you want to show all the posts?

if so, edit the code like this


 //get the blog posts as the parameters provided
   function blogPosts(){
      $posts = DataObject::get('BlogEntry', 'ParentID = ' . $this->Blog, 'Date DESC');
      return $posts;
   } 

Go to Top