Jump to:

1835 Posts in 1139 Topics by 554 members

Blog Module

SilverStripe Forums » Blog Module » Latest news on home page from two blog holders

Discuss the Blog Module.

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

Page: 1
Go to End
Author Topic: 1531 Views
  • Mitz
    Avatar
    Community Member
    9 Posts

    Latest news on home page from two blog holders Link to this post

    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: http://www.silverstripe.org/blog-module-forum/show/261584#post261584. 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.

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Latest news on home page from two blog holders Link to this post

    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.

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