1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Top Rated Threads - request - code - outside XF

Discussion in 'XenForo Development Discussions' started by Netsultants, Dec 4, 2010.

  1. Netsultants

    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.
  2. Shadab

    Shadab Well-Known Member

    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.
  3. Netsultants

    Netsultants Active Member

    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.
  4. Brogan

    Brogan XenForo Moderator Staff Member

    Is this an add-on request or are you going to be writing it yourself and you're looking for help with the code?
  5. Netsultants

    Netsultants Active Member

    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.
  6. Brogan

    Brogan XenForo Moderator Staff Member

    No worries, I just wanted to make sure the thread was in the correct forum :)
  7. Netsultants

    Netsultants Active Member

    Thanks Man!
  8. Shadab

    Shadab Well-Known Member

    For a start...
    (assuming you've already initialized the xenforo framework)

    $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;

    $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
    Netsultants likes this.
  9. Netsultants

    Netsultants Active Member

    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

Share This Page