17488 Posts in 4473 Topics by 1978 members
| Go to End | ||
| Author | Topic: | 3405 Views |
-
Re: How do I get the latest forum posts shown on the homepage?

24 April 2008 at 11:01pm Last edited: 24 April 2008 11:49pm
find your Page.php file which will be the basis of your homepage.. unless you have changed it.
add this after the function init() like below..
class Page_Controller extends ContentController {
function init() {
....
}/**
* 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) {
$posts = DataObject::get("Post", "ForumID != 0", "Created DESC", "", $limit);
return $posts;
}}
-
Re: How do I get the latest forum posts shown on the homepage?

25 April 2008 at 11:04am
thanks for that advice - it's solved that error message but unfortunately it doesn't return any posts.
I've found there are 2 LatestPost functions, one in Forum.php and one in Post.php (both in forum/code).
Post.php:
function LatestPost() {
$filter = "";
if($this->ParentID != 0) {
$parents = $this->getDescendantIDList();
$parents[] = $this->ID;
$filter = "AND ParentID IN (" . implode(",", $parents) . ")";
}
$posts = DataObject::get("Post", "TopicID = $this->TopicID $filter",
"Created DESC", "", 1);
if($posts) return $posts->First();
}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();
}
}As you can see, they are similar but different.
And now I have 2 LatestPosts functions, one also in Forum.php and one in mysite/code/page.php as per the code posted in previous messages
So it compiles and runs, but doesn't actually produce any code in the resulting html. HELP!
-
Re: How do I get the latest forum posts shown on the homepage?

25 April 2008 at 11:31am
try taking the $limit variable out of the function and from your on page controller and set it manually to check it isn't that. Sorry, i didn't test it.
| 3405 Views | ||
| Go to Top |

