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.

Archive /

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
Reply


11 Posts   3984 Views

Avatar
Foweyboy

Community Member, 7 Posts

23 April 2008 at 11:23pm

Hi,

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: www.vaRnishingCornwall.co.uk

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:
ERROR:
Error

The website server has not been able to respond to your request.
At the following address:
http://varnishingcornwall.co.uk/ForumMemberProfile/?executeForm=RegistrationForm
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

Avatar
Blackdog

Community Member, 156 Posts

23 April 2008 at 11:26pm

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.

Avatar
Sam

Administrator, 685 Posts

24 April 2008 at 9:13am

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

Avatar
Foweyboy

Community Member, 7 Posts

24 April 2008 at 11:00am

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);
         if($posts)
            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:
LatestPost(4);

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

Also any thoughts on the little errors I am experiencing?

Avatar
Sean

Forum Moderator, 922 Posts

24 April 2008 at 11:52am

Edited: 24/04/2008 11:54am

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.

Sean

Avatar
Foweyboy

Community Member, 7 Posts

24 April 2008 at 8:57pm

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 page.ss.
Unfortunately when I flushed/refreshed the page it threw this error:

Parse error: syntax error, unexpected $end in /tmp/silverstripe-cache-home-1658-caliban-www.varnishingcornwall.co.uk-public_html/.cache.home.1658.caliban.www.varnishingcornwall.co.uk.public_html.themes.freestyle.templates.Page.ss on line 328

Any ideas?

Avatar
Blackdog

Community Member, 156 Posts

24 April 2008 at 9:20pm

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 %>

Avatar
Foweyboy

Community Member, 7 Posts

24 April 2008 at 10:20pm

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

Go to Top