Jump to:

10931 Posts in 2614 Topics by 1810 members

All other Modules

SilverStripe Forums » All other Modules » News module or extension

Discuss all other Modules here.

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

Page: 1 2 3
Go to End
Author Topic: 5931 Views
  • Marcus
    Avatar
    Administrator
    86 Posts

    Re: News module or extension Link to this post

    Makes sense - have added them as bugs on the github page @ https://github.com/nyeholt/silverstripe-news/issues

  • Mindfusion
    Avatar
    Community Member
    7 Posts

    Re: News module or extension Link to this post

    Hey Marcus , trying out your news module (very nice work btw) . The main reason i am using the module is i need to automatically archive / file news articles by their published date. I am trying to create a latest news function that would pull the latest 5 published news articles and display them on the home page. I modified the function from the ss tutorial 2 but it doesn't seem to be pulling any records . Could you give me any pointers on how to achieve this? The code for the function is below

    function LatestNews($num=5) {
        $news = SiteTree::get_by_link('news');
    return ($news ) ? DataObject::get("NewsArticle", "ParentID = $news ->ID", "OriginalPublishedDate DESC", "", $num) : false;
    }

    Thanks

  • Terry Apodaca
    Avatar
    Community Member
    109 Posts

    Re: News module or extension Link to this post

    Mindfusion, This is the code I used to get the 2 most recent on the home page...so it shouldn't be hard at all to get 5 like you need:

    function LatestNews($num=2) {
          
       $news = DataObject::get("NewsArticle","","OriginalPublishedDate DESC","",$num);
          
       return $news;
    }


    and yes, I am using this same module so it should be a simple copy/paste for you, then change the $num=2 to $num=5.

  • Mindfusion
    Avatar
    Community Member
    7 Posts

    Re: News module or extension Link to this post

    Hi Terry , It worked ! Thanks a lot

  • Ronaldo71
    Avatar
    Community Member
    9 Posts

    Re: News module or extension Link to this post

    Hi,

    Congrats for the module, works fine and just what I needed. One suggestion though:
    While on a NewsArticle page, I'd like to have a list with other articles in a sidebar.
    If I'm not the only one here, isn't it useful to add a method to the NewsArticle class that pulls out other articles with the method you described above?

    Now, I'm subclassing the NewsArticle class just for this method:

    class MyCustom_NewsArticle extends NewsArticle {

       public static $icon = 'news/images/newspaper';
       public static $db = array();
       public static $has_one = array();

       public function Articles() {
          $holder = new NewsHolder();
          return $holder->Articles();
       }

    }

    class MyCustom_NewsArticle_Controller extends Page_Controller {
       
    }

    But that kinda pollutes my Pagelist (to choose from) with another Page type, and NewsArticle alone just looks fine (And easier to explain to future users of my client).
    Well, maybe there's another way, I just started with SilverStripe ;)

    Ronald

  • erbaayunusemre
    Avatar
    Community Member
    1 Post

    Re: News module or extension Link to this post

    Hi,

    I tried the module and it is really great. But I want to show the news on homepage. I see the code you use but I don't know where to paste these codes. If you can help me, I will be very glad. Thanks...

  • Terry Apodaca
    Avatar
    Community Member
    109 Posts

    Re: News module or extension Link to this post

    If you are referencing my code, you can place it in your custom HomePage.php (I always put it in the Controller). Or you can put that code in the Page.php so you can actually access the news from anywhere in your site since most of your custom pages (if you have custom pages) will extend Page.php.

  • Anas
    Avatar
    Community Member
    4 Posts

    Re: News module or extension Link to this post

    Does this work with ss3? i copied the code in the customehomepage.php but still cant see the latest news on the page any help pls..

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