Jump to:

794 Posts in 409 Topics by 304 members

Widgets

SilverStripe Forums » Widgets » LatestBlogPost widget problem - Fixed

Discuss SilverStripe Widgets.

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

Page: 1
Go to End
Author Topic: 1964 Views
  • Web Designer Perth
    Avatar
    Community Member
    49 Posts

    LatestBlogPost widget problem - Fixed Link to this post

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

    }

    ?>

  • Web Designer Perth
    Avatar
    Community Member
    49 Posts

    Re: LatestBlogPost widget problem - Fixed Link to this post

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

    }

    ?>

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: LatestBlogPost widget problem - Fixed Link to this post

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

  • arthurdent
    Avatar
    Community Member
    161 Posts

    Re: LatestBlogPost widget problem - Fixed Link to this post

    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?

    1964 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.