nickyates
12 years agoMentor
sorting forum posts by the number of messages in each post
I am trying to make a custom component which displays the 3 forum posts with the most comments. I am having trouble displaying the posts in decending numerical order of the number of comments each post has. is there a way to do this using either the API or Freemarker? Please could you provide an short example? Thanks
Here's an alternate approach that may work for what you're trying to do:
One downside is that you'd have to make a separate REST API call per message to get the number of replies, ie.
/messages/id/1234/replies/count
You can use the href attribute to make it easier, though. For example:
<#assign messages=rest("/search/messages?q=is_root:true&sort_by=-replies").messages /> <ul> <#list messages.message as message> <#assign count = rest(message.@href + "/replies/count").value /> <li>${message.id} - ${count}</li> </#list> </ul>
I hope this helps!