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.

Widgets /

Discuss SilverStripe Widgets.

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

LatestBlogPost widget problem - Fixed


Reply


4 Posts   1989 Views

Avatar
Web Designer Perth

Community Member, 49 Posts

27 July 2009 at 10:13pm

Edited: 29/07/2009 7:15pm

I am using this widget and it works very well _except_ that it does not pick up the number of posts to show, as set in the cms.

Can anyone see why? Or perhaps help me hard-code a fixed number (avoiding calls to the db). I really need to get this fixed for the dogs' refuge site I built and everything I've tried results in whitepage or website error.

TIA

<?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
Web Designer Perth

Community Member, 49 Posts

29 July 2009 at 7:14pm

Fixed thanks to Nivanka:

<?php

// LatestBlogPost Widget 0.0.2 for the SilverStripe Blog Module
// 28.07.2009
// By nivanka@whynotonline.com
// Save this and LatestBlogPost.ss to widget_latestblogpost/ and run "db/build".
// This module allows you to add a suggestion form field to your forms.

class LatestBlogPost extends Widget{

   static $title = "Latest Blog Post";
   static $cmsTitle = "Latest Blog Post";
   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, 395 Posts

1 August 2009 at 3:37am

the latest build is available to download here [url]http://open.whynotonline.com/latest-blog-post/[/url]

Avatar
arthurdent

Community Member, 167 Posts

4 May 2011 at 11:21am

Edited: 04/05/2011 11:22am

I'm having no luck with this widget and am wondering what I'm doing wrong. All I'm getting is a message that there are no blog posts available. I did update my PHP file with Nivanka's 28.07.2009 fix - which then crashed SilverStripe! And the link in the post above doesn't work any more. Have emailed Nivanka to no avail - can anybody offer any advice?