Top Rated Threads - request - code - outside XF

Netsultants

Active member
I don't think this feature is implemented in XF. I know there is a like button for posts but is there a like button for threads?

I have a "Top Rated" on the front page of http://www.allergychat.org . I'd like to implement the same look with threads from the forum.

Anyone else think this is a good idea? Maybe an admin function to adjust certain threads so they are always on the home page.

I got to thinking about this after reading the thread about "recent post" code outside XF.
 
The thread table in xenforo (xf_thread) has a field "first_post_likes".
You can do an order by using that field in descending order, to mimic your "Top Rated" functionality.
 
That makes sense, I think you're right. Since the first post is the topic of the thread it should mimic the functionality.

Adding to this functionality, I thought it would be good if an admin had the ability to move a thread up easily so that it appeared on this "Top Rated" threads list or some other list that could be created.
 
Is this an add-on request or are you going to be writing it yourself and you're looking for help with the code?
 
Hey Brogan, I think it's functionality that might be great in the core code. Giving the admin the ability to tag threads "Top threads" lists

As far as implementing the functionality outside of XF, I could certainly use some help with the code.
 
No worries, I just wanted to make sure the thread was in the correct forum :)
 
For a start...
(assuming you've already initialized the xenforo framework)

PHP:
$threadModel = XenForo_Model::create('XenForo_Model_Thread');
$searchModel = XenForo_Model::create('XenForo_Model_Search');

$fetchOptions = array(
	'limit' => 10,
	'order' => 'first_post_likes',
	'orderDirection' => 'desc',
);

$conditions = array(
	'deleted' => false,
	'moderated' => false
);

$threads = $threadModel->getThreads($conditions, $fetchOptions);

foreach ($threads as $threadId => &$thread)
{
	$thread['content_type'] = 'thread';
	$thread['content_id'] = $threadId;
}
unset($thread);

$threads = $searchModel->getViewableSearchResults($threads);

This would fetch the top 10 "most-liked" threads ($threads) and then filter out the results based on the viewing user's permissions (using the Search model).

There's one catch: the "limit" is applied when fetching the threads, so if a "private" thread is returned, the search model will remove it from the list and you'd end up displaying 9 threads. This is kind-of undesirable, but hey, not as much as displaying that private thread itself. :P
 
...............the search model will remove it from the list and you'd end up displaying 9 threads. This is kind-of undesirable, but hey, not as much as displaying that private thread itself. :p

Yep I agree... I think it's a great start. Thanks.

I'll attempt implementing it and get back to you when I screw it up. :D
 
Top Bottom