Support » Plugins » Hacks » Front end comment sorting

  • I’m trying to figure out a way to sort my comments. I’m using the comments rating plugin which adds karma to the comment.

    I want viewers to be able to sort the comments from newest to oldest and from highest rated karma to lowest.

    I’ve figured out how to sort them, but I DO NOT know how to create a link or interface that gives viewers the option to select different sort methods.

    I tried this method:
    – It works in displaying the comments, but the comment form seems to only process on the default tab — this means when I click reply on a comment that is on the 2nd tab, the comment form collapses on the first tab. Is there maybe a way to reload the content so it thinks its a fresh process when clicking between the tabs?

    Any other suggestions? I’ve been researching for hours on end per day and this is stumping me 🙁

    Thanks guys!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz


    Use AJAX like techniques to re-query the comments and generate new content for the comments container. Place some element on your comment template that users can interact with, it can be text, a button, a pulldown field, an image, whatever. Some event like a click or change on this element will trigger a jQuery .post() request to WP’s AJAX handler with the post ID and orderby parameters.

    Your PHP AJAX callback will take the POSTed data and form a new comment query ordered appropriately and generate content in the same manner as the comment template would. The jQuery .post() callback receives this content and replaces the old comment content in the comments container with the new content.



    Thank you for the response, unfortunately, I do not know any jquery or ajax — so I am a little lost. Maybe you can link me to something more in depth? So sorry :/


    Moderator bcworkz


    Well, there’s AJAX in Plugins. It leaves something to be desired, unfortunately. The Further Reading links are helpful though.

    Perhaps the first step in implementing this is to alter your comment template to accept orderby arguments POSTed (or GET’d) by a conventional HTML form, resulting in simply reloading the entire page with the revised comment sort.

    Once you get the mechanics of that working, you can focus on the AJAX portion to achieve the more interactive, seamless user experience you are looking for.

    A divide and conquer approach with usable intermediate results will make learning new techniques more enjoyable and rewarding IMO. Good luck.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Front end comment sorting’ is closed to new replies.