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.


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

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

How do I get the latest forum posts shown on the homepage?

Go to End

11 Posts   3927 Views


23 April 2008 at 11:23pm Community Member, 7 Posts


I've just made my first Silverstripe website and I've been very impressed by how quick and easy it has been. Check it out:

I've got 2 minor problems and 1 question, all related to the forum module. My question first:
1. How do I get the latest forum posts shown on the homepage?

And my problems:
2. If a forum member uses the upload avatar feature the new member account creation fails with the following message:

The website server has not been able to respond to your request.
At the following address:
3. When a user wishes to sign out of the forum they have to click "Log Out" twice for some reason - the first time it refreshes the page but you are still logged in.

Hope someone out there can help! Thanks


23 April 2008 at 11:26pm Community Member, 156 Posts

checkout the LatestPost() function in the forum code, you could do a call to that control within the Forum control.

Or replace that function in your homepage controller.

let us know how you go.


24 April 2008 at 9:13am Administrator, 679 Posts

I also seem to recall that someone made a latest posts widget?


24 April 2008 at 11:00am Community Member, 7 Posts

Hi guys thanks for you help.

I've found the following section of code in Forum.php
    * Get the latest posting of the forum
    * @return Post Returns the latest posting or nothing on no posts.
    * @todo This is causing some errors, temporarily added is_numeric.
   function LatestPost() {
      if(is_numeric($this->ID)) {
         $posts = DataObject::get("Post", "ForumID = $this->ID",
                                              "Created DESC", "", 1);
            return $posts->First();

Am I right in thinking I can just call this function in the homepage's .ss file, and it'll list the last x latest posts out? something like:

And I get the 4 latest posts? Or have I blundered?

Also any thoughts on the little errors I am experiencing?


24 April 2008 at 11:52am (Last edited: 24 April 2008 11:54am), Forum Moderator, 921 Posts

This should work:

* Get the latest posts from the forum, with a limit.
* @param Int $param The number of posts to retrieve
* @return Post Returns the latest posting or nothing on no posts.
function LatestPosts($limit) {
return DataObject::get('Post', '', 'Created DESC', '', (int)$limit);

Then call <% control LatestPosts(5) %> in the template, I think.



24 April 2008 at 8:57pm Community Member, 7 Posts

Hi there - thanks for your help!

I added the LatestPosts function to the Forum.php file, just under the LatestPost function, and added the calling line to my theme's
Unfortunately when I flushed/refreshed the page it threw this error:

Parse error: syntax error, unexpected $end in /tmp/ on line 328

Any ideas?


24 April 2008 at 9:20pm Community Member, 156 Posts

you will want to add the function to your page controller class that extends the Page_Controller.

That way you will hve access to it as a on page <% control LatestPost %>


24 April 2008 at 10:20pm Community Member, 7 Posts

I can't find the "Page_Controller" code/file- where is it?

Go to Top