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.

Blog Module /

Discuss the Blog Module.

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

Latest news on home page from two blog holders

Go to End

2 Posts   2023 Views


Community Member, 10 Posts

21 May 2010 at 4:59pm

Hi there,

I have two blogs that I'm using on a current build. Wish to show latest posts from both these blogs on the home page. eg. 2 under Latest News and 1 under Latest Research.

I can see how to specify the blog from: However when I try to add both to my code, I get the following error:

Fatal error: Cannot redeclare HomePage_Controller::LatestNews() in /home/fxmed/public_html/silverstripe/mysite/code/HomePage.php
on line 35

Any ideas? Thanks people.


Forum Moderator, 5523 Posts

21 May 2010 at 8:17pm

You can't have 2 functions called the same. Either rename the 2nd one or use pass an argument to work out which holder to use. For example if you did <% control LatestNews(blog) %> and <% control LatestNews(news) %> and you could use 1 function to do both and just swap on the variable you pass

function LatestNews($title) {
$news = DataObject::get_one('ArticleHolder', "URLSegment = '$title'");

return ($news) ? DataObject::get("ArticlePage", "ParentID = $news->ID", "Date DESC", '', 10) : false;

That 2nd line will get you the article holder by the URL you pass into the function.