Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

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

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

Is there a news module?

Go to End

12 Posts   7743 Views


Community Member, 46 Posts

26 April 2007 at 7:11am

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?


Forum Moderator, 5523 Posts

26 April 2007 at 8:13pm


Forum Moderator, 922 Posts

26 April 2007 at 8:54pm

Edited: 26/04/2007 9:00pm

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 (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:

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) %>
<% end_control %>
<% 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 %>
<% control Articles.Pages %>
<% if CurrentBool %>$PageNum<% else %><a href="$Link" title="View page number $PageNum">$PageNum</a><% end_if %>
<% end_control %>
<p>Page $Articles.CurrentPage of $Articles.TotalPages</p>
<% 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,



Forum Moderator, 5523 Posts

26 April 2007 at 9:08pm

Edited: 26/04/2007 9:11pm

Yo Sean, we (that I mean Ingo :P) 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 :D if it doesn't I will post my (Ingos*) code


Forum Moderator, 922 Posts

26 April 2007 at 9:17pm

Edited: 26/04/2007 9:19pm

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.


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


Community Member, 33 Posts

27 April 2007 at 7:19am

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.


Forum Moderator, 922 Posts

27 April 2007 at 9:43am

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



Forum Moderator, 801 Posts

27 April 2007 at 12:40pm

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.

Go to Top