Hi, I'm not very experienced at Silverstripe, and the guy who helped me build our uni department's site was a student here and has gone. This is probably really easy but it's driving me nuts.
We have news articles, which are held in a news holder page, but the three most recent news articles are also displayed on our homepage. Because of this, and because we want the articles to be displayed in order of time (most recent first) instead of the order they appear in the CMS , we are not using <% control Children %> to display the news articles. Instead, we have a function which lives in the NewsHolder Controller:
function LatestNews() {
$news = DataObject::get_one("NewsHolder");
return ($news) ? DataObject::get("NewsArticle", "ParentID = $news->ID", "Date DESC", "") : false;
}
This was all very good, and worked well until I decided I needed to archive some of the articles into separate newsholder pages. I created the new pages and moved the articles into the appropriate parents, and then of course, each parent displayed every news article. I solved this problem, mostly, by making a new page type for archives which just uses control children instead of control LatestNews. But, I am STILL getting one article from one of the archive pages displaying at the bottom of my list. Here is a link. It's a cached page, but looks the same even if you look at the non-cached version. http://biochem.otago.ac.nz/news/
So I need help. I can't understand why I am getting one article from 2009 at the bottom of this newsholder page. It is definitely a child of the 2009 archive page, and there is only one copy of it. I've save-and-published numerous times and the bloody thing still keeps turning up.
A second issue is functions. I tried to work around the above by making a function that would return true if the date on the news article was from the current year, but it's just not working and I'd like to know why - even if I can get rid of that article in a more sensible fashion.
This is the function I made:
function ThisYear() {
$date = $this->Date;
if ($date->Year() == ($now->Year())){
return true;
} else {
return false;
}
}
I wasn't sure where to put it, so I tried it in the controller part of my news article page. The database rebuilds OK, but I don't get any articles showing up when I use <% if ThisYear %> in my template page. Can someone please tell me what I'm doing wrong? I do have a Date field in my news articles.