• Welcome to Tux Reports: Where Penguins Fly. We hope you find the topics varied, interesting, and worthy of your time. Please become a member and join in the discussions.

Comments Ranked by Likes

This entry is part of a series of entries "February 2017 - XenWord Development Log"
Likes.jpg


A new widget was developed for XenWord 3.3.3 which shows the comments of a WordPress post sorted by the number of likes. I couldn't figure out a way to do this with a model, therefore, a replies queries was created and used to fetch all of the values. These replies were sent through a simple foreach loop.

PHP:
/** @var $thread_qry XenWord_Comment_Ranking */
$replies_qry = "
               SELECT thread_id, post_id, user_id, message_state, likes, message, position FROM `xf_post`
               WHERE message_state = 'visible' AND thread_id = $threadId
               ORDER BY `likes` DESC
               LIMIT $number_of_posts
            ";

$replies = XenForo_Application::get( 'db' )->fetchAll( $replies_qry );

As the widget was being developed, I came across an interesting question. What if the widget was trying to load on a page or the frontpage of the site? What if the post didn't have a thread associated with it?

This initially returned an error and so I put in a conditional for testing these conditions. The conditional blocked the loading. Great !

Next, I realized the widget could be blocked under other conditions, too. For example, a staff online widget should not show if a staff member is not online.

Here is a video showing the work.

Previous entry in series Checkbox Option For Thread Creation
  • Like
Reactions: robru

Blog entry information

Author
LPH
Views
522
Last update

More entries in General

More entries from LPH

Top