Jump to:

1856 Posts in 1610 Topics by 562 members

Blog Module

SilverStripe Forums » Blog Module » Q: Multiple blogs with latest post on HomePage

Discuss the Blog Module.

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

Page: 1 2 3
Go to End
Author Topic: 5721 Views
  • OnebyOne
    Avatar
    Community Member
    54 Posts

    Q: Multiple blogs with latest post on HomePage Link to this post

    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

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: Q: Multiple blogs with latest post on HomePage Link to this post

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

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: Q: Multiple blogs with latest post on HomePage Link to this post

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

    Attached Files
  • Web Designer Perth
    Avatar
    Community Member
    49 Posts

    Re: Q: Multiple blogs with latest post on HomePage Link to this post

    @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.

  • Web Designer Perth
    Avatar
    Community Member
    49 Posts

    Re: Q: Multiple blogs with latest post on HomePage Link to this post

    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.

  • George
    Avatar
    Community Member
    41 Posts

    Re: Q: Multiple blogs with latest post on HomePage Link to this post

    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

  • Web Designer Perth
    Avatar
    Community Member
    49 Posts

    Re: Q: Multiple blogs with latest post on HomePage Link to this post

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

    }

    ?>

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: Q: Multiple blogs with latest post on HomePage Link to this post

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

    5721 Views
Page: 1 2 3
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.