Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Is there a news module?

Our old forums are still available as a read-only archive.

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

Page: 1 2
Go to End
Author Topic: 6756 Views
  • sarahk
    Avatar
    Community Member
    46 Posts

    Is there a news module? Link to this post

    I need a news section on my site but rather than creating a very long list of subpages I'd like to have a list of the last 10 (for example) and the ability to filter by month or search on content.

    So on the tree I'd just have the "holder" and the holder page would have the list. Click on an item and I'd be able to edit just like a normal page (with standard silverstripe modifications).

    Has anyone done something like this?

  • Willr
    Avatar
    Forum Moderator
    5489 Posts
  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Is there a news module? Link to this post

    In terms of filtering by month, I myself haven't attempted to create such a function. But you could attempt making a function like this, which would come out something like this http://www.mycoolsite.com/news/april (calling the method)... using urlParams like so:

    function showarchive() {
    $month = addslashes($this->urlParams['ID']);
          
    return array(
    'Children' => DataObject::get('NewsArticle', 'ParentID = $this->ID AND DATE_FORMAT(`NewsArticle_Live`.`Date`, "%Y-%M") = "$month"'),
          );
    }

    Note: I have no idea if this actually works, it's just an idea I've been toying with. I do believe a news module would be nice, though, with all these helper functions already there to use.

    In terms of searchable news content - this works out of the box if you implement the search tutorial found here: http://doc.silverstripe.com/doku.php?id=tutorial:4-site-search

    Having the last 10 articles you can filter by the Date defined on the NewsArticle page's Date field. eg. a function on the NewsHolder class:

    function Articles($pageLimit = 10) {
          
    // checks to ensure limit is correctly set
    if(!is_numeric($pageLimit)) $pageLimit = 0;
    if($pageLimit == null) $pageLimit = 0;
          
    // checks to ensure start variable is correctly set
    if(!is_numeric($_REQUEST['start'])) $_REQUEST['start'] = 0;
    $limit = $_REQUEST['start'] . ',' . $pageLimit;
          
    $callerClass = 'NewsArticle';
    $filter = '`ShowInMenus` = "1" AND `ParentID` = "{$this->ID}"';
    $sort = '`NewsArticle_Live` . `Date` DESC';
          
    $entries = DataObject::get($callerClass,$filter,$sort,'',$limit);
    return $entries;
    }

    In your template you would call like this, note the parameter for the control, which you can change in the template itself, overriding the default of 10 we defined above. Good for separation of code from template.

    <% if Articles %>
    <ul class="articleList">
    <% control Articles(15) %>
    <li>
    <h3>$Title</h3>
    <p>$Content.FirstParagraph(html)</p>
    </li>
    <% end_control %>
    </ul>
    <% end_if %>

    <% if Articles.MoreThanOnePage %>
    <div id="PageNumbers">
    <% if Articles.NotLastPage %>
    <a class="next" href="$Articles.NextLink" title="View the next page">Next</a><% end_if %><% if Articles.NotFirstPage %><a class="prev" href="$Articles.PrevLink" title="View the previous page">Prev</a><% end_if %>
             <span>
           <% control Articles.Pages %>
                      <% if CurrentBool %>$PageNum<% else %><a href="$Link" title="View page number $PageNum">$PageNum</a><% end_if %>
                <% end_control %>
             </span>
             <p>Page $Articles.CurrentPage of $Articles.TotalPages</p>
          </div>
       <% end_if %>

    Note the extra MoreThanOnePage controls here. These are available if you've got more than 15 articles, so it allows for pagination. To get this out of the box, you need to make sure you've set the limit in your DataObject::get as a limit starting at record. eg 1,5... which gets 5 records from the database starting at record 1.

    Hope this helps,

    Cheers,
    Sean

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Is there a news module? Link to this post

    Yo Sean, we (that I mean Ingo ) wrote a function to browse by month for the upcoming blogging module. (Maybe we can have a separate news module aswell?)

    I havent tested your code but I'm sure it works if it doesn't I will post my (Ingos*) code

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Is there a news module? Link to this post

    That function I haven't tested. But since the blog module works pretty much one in the same as basic news articles that would be awesome!

    I think we should basically just combine all our ideas for news/blogs and throw them into one - a blog module.

    Thoughts?

    Oh, and if you guys are still at work - go home!

  • pouderStream
    Avatar
    Community Member
    33 Posts

    Re: Is there a news module? Link to this post

    I think they should be separeted. Argument for that is that if they are different modules they could be easily extended in the future. Besides what if modules get too different in functionality? There will be chunk of code, don't u think

    Anyway both ideas are great.

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Is there a news module? Link to this post

    We've found that from the development work here in the office that using a blog works one in the same for news as well.

    Things like article archiving work in the same way with news as it does with blog entries.

    If you don't want the specific blog features (comments, tagging etc) then you'd just turn those features off yourself, then you've got a basic news article system.

    Maintaining the module would be a lot easier (since there's only one).

    Cheers,
    Sean

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Is there a news module? Link to this post

    pouderStream: interesting thought (separating into "news" and "blog" modules).
    what features do you see as exclusive to one module? i had a quick chat with sean about it this morning, we couldn't really come up with any.
    i've worked a lot with typo3 before, they build their blog-module ("timtab") on top of news ("tt_news"), but thats more a hack/workaround than an architectural decision. i'd also tend to only have a "blog" module for easier maintenance and a shared codebase.

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