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