Jump to:

1844 Posts in 1600 Topics by 559 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: 5613 Views
  • Web Designer Perth
    Avatar
    Community Member
    49 Posts

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

    How? Say if I only want the six latest posts?

  • dab
    Avatar
    Community Member
    50 Posts

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

       function getLatestBlogEntries($number=6) {   
          return DataObject::get('BlogEntry', "","Date DESC", false, $number);
       }

  • Nivanka
    Avatar
    Community Member
    395 Posts

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

    no need of editing anything then, just on the widgets backend put 6 where it asks you how many posts you need to show.

  • Web Designer Perth
    Avatar
    Community Member
    49 Posts

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

    Hi Nivanka, I have done that but it's not working. Hence my earlier post in this thread.

    I will hard-code and see - thx dab.

  • AlfonsoGrondo
    Avatar
    Community Member
    2 Posts

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

    Hi,

    I'd like to do the same as the original post in this thread... pull together multiple blogs into a news site (simple site of multiple categories). Wondering how would I set this up.. duplicating BlogHolder as OneByOne mentioned? Would that be the preferred way to manage something like that or simply take advantage of tag cloud and use that as 'categories'? Any advice appreciated.

    Thanks

  • Nivanka
    Avatar
    Community Member
    395 Posts

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

    hi,

    I added a new build of the widget at http://open.whynotonline.com/latest-blog-post/

    This might solve your problem.

    thanks

  • WalterW
    Avatar
    Community Member
    18 Posts

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

    I changed the layout for the latest post widget. I don't like to show the whole post entry, as it can be quite large. Also I delete the html entities like Breakks or Urls or ...

    So I show the source code (for LatestForumPostWidget.php) to do this:

    <?php
       
       class LatestForumPostWidget extends Widget{

          //The widget info
          static $title = "Newest Posts";
          static $cmsTitle = "Newest Posts";
          static $description = "This widget displays latest forum post on the side bar, you need to install the Forum module to make use of this widget";

          protected static $MaxNrLines=3;
          protected static $MaxNrPosts=3;
          
       /**
        * Set max number of lines per post to display
        *
        * @param integer $val
        */
       public static function set_max_nr_lines($val) {
          self::$MaxNrLines = $val;
       }
       /**
        * Set max number of posts to display
        *
        * @param integer $val
        */
       public static function set_max_nr_posts($val) {
          self::$MaxNrPosts = $val;
       }

          //Return the latest
          function getPosts(){
             $output=null;
             $posts = DataObject::get("Post", "", "Created DESC", "" , self::$MaxNrPosts);
             // $ThisPost=$posts->First();
             if ($posts->exists()) {
             $output = new DataObjectSet();
             foreach($posts as $ThisPost) {
                $PostLines = "";
                $PostTextCtr=1;
                $PostTextLine = strtok($ThisPost->Content,"\n");
                while ($PostTextLine !== false && $PostTextCtr<=self::$MaxNrLines) {
                   $PostLines .= $PostTextLine ;
                   if (++$PostTextCtr<=self::$MaxNrLines) { $PostLines .= "<br>"; }
                   $PostTextLine = strtok("\n");
                }
                // delete html-Entities
                $PostLines=preg_replace("/\[[a-z\/A-Z0-9]+\]/","",$PostLines);
                $output->push(new ArrayData(array(
                "Link" => $ThisPost->Link(),
                "Title" => $ThisPost->title,
                "Content" => $PostLines . "<a href=\"" . $ThisPost->Link() . "\"> .....</a>"
                )));
             }
             }
             return $output;
          }
       }

    ?>

  • biapar
    Avatar
    Forum Moderator
    435 Posts

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

    Question:

    - how can I create multiple blog entry?
    - how can I create categories?

    Thank you

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