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.

Blog Module

Discuss the Blog Module.

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

Q: Multiple blogs with latest post on HomePage


Go to End
Reply

17 Posts   5724 Views

Avatar
OnebyOne

4 May 2009 at 9:19pm Community Member, 54 Posts

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

11 May 2009 at 1:00am Community Member, 395 Posts

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

7 June 2009 at 4:12pm Community Member, 395 Posts

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

Attached Files
Avatar
Web Designer Perth

12 June 2009 at 6:52pm Community Member, 49 Posts

@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

15 June 2009 at 11:21am Community Member, 49 Posts

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

17 June 2009 at 7:54am (Last edited: 17 June 2009 7:55am), Community Member, 41 Posts

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>'")
...

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

Avatar
Web Designer Perth

3 July 2009 at 1:16pm (Last edited: 5 July 2009 4:02pm), Community Member, 49 Posts

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

5 July 2009 at 9:58pm Community Member, 395 Posts

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