Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » How do I get the latest forum posts shown on the homepage?

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

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

Page: 1 2
Go to End
Author Topic: 3888 Views
  • Foweyboy
    Avatar
    Community Member
    7 Posts

    How do I get the latest forum posts shown on the homepage? Link to this post

    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

  • Blackdog
    Avatar
    Community Member
    156 Posts

    Re: How do I get the latest forum posts shown on the homepage? Link to this post

    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.

  • Sam
    Avatar
    Administrator
    679 Posts

    Re: How do I get the latest forum posts shown on the homepage? Link to this post

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

  • Foweyboy
    Avatar
    Community Member
    7 Posts

    Re: How do I get the latest forum posts shown on the homepage? Link to this post

    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?

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: How do I get the latest forum posts shown on the homepage? Link to this post

    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

  • Foweyboy
    Avatar
    Community Member
    7 Posts

    Re: How do I get the latest forum posts shown on the homepage? Link to this post

    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?

  • Blackdog
    Avatar
    Community Member
    156 Posts

    Re: How do I get the latest forum posts shown on the homepage? Link to this post

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

  • Foweyboy
    Avatar
    Community Member
    7 Posts

    Re: How do I get the latest forum posts shown on the homepage? Link to this post

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

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