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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

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

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

Archive the news?


Go to End


3 Posts   2661 Views

Avatar
abelcreative

4 Posts

9 August 2007 at 1:51am

I installed this for a client - and now they're asking for a way to archive their news. Any way to do that?

Avatar
Sam

Administrator, 690 Posts

9 August 2007 at 3:37pm

The easier is to create a different page called "news archive", and get your client to drag the old pages into that.

If you want to do it automatically, you could write a different Children() method on your news page that only listed the 10 most recent items, and an ArchiveChildren() method that will return older items:

function Children() {
  // return the current items;
}
function ArchiveChildren() {
  // return archived items
}

function archive() {
  return array(
    "Children" => $this->ArchiveChildren(),
  );
}

That way, you have two URLs:
* http://www.mysite.com/news/ - the news
* http://www.mysite.com/news/archive - the news archive.

What happens is this:
* When you visit news/archive, it uses the archive action to visit the news page
* This means that the archive() method gets called on the controller object.
* Since it returns an array, this is interpreted as being changes to the controller data. In this case, we've provided new data for <% control Children %>

You can also, if you want, make a new template called (classname)_archive.ss

Avatar
redking

43 Posts

14 April 2008 at 9:52am

Hi Sam,

I'm trying to achieve the same thing.
Do those two methods need to be placed in the in the ArticleHolder class?
I copy/pasted them in there, but I'm having a hard time getting it to work.
Also, how do I specify only displaying the five most recent articles?

Thanks!