sorting forum posts by the number of messages in each post
Hi,
I have a category called help (categories/id/5678). Within help there are several 7 forums. I would like to display the names of the forums along with how many messages in total there are in each forum ordered by the number of messages. currently my code looks like this:
<#assign boards = rest("categories/id/5678")>
<table class="lia-list-wide">
<thead id="columns">
<tr>
<th scope="col" >Title</th>
<th scope="col" ">Comments</th>
</tr>
</thead>
<tbody>
<#list boards.category.boards.board as c>
<tr>
<td colspan="1" rowspan="1">
<h3><a id="link_13" id="link_13">${c.title}</a></h3>
<div>${c.description}</div>
</td>
<td rowspan="1" colspan="1">
Message count here
</td>
</tr>
</#list>
</tbody>
</table>
I had a similar question here (https://lithosphere.lithium.com/t5/developers-discussion/sorting-forum-posts-by-the-number-of-messages-in-each-post/m-p/81670#M2848) which helped on a similar issue but i just cant seem to get this to work using that code example.
Thanks!
Hi Yuri,
That was exactly what i was after, i did make one small change, i added in ?number after /messages/count").value as it was treating the numbers as text and was putting the boards in a slightly wrong order.
<#assign boards = rest("categories/id/5678/boards").boards/>
<#assign order_list = []/>
<#list boards.board as c>
<#assign one_index_obj = {"count":rest("/boards/id/${c.id}/messages/count").value?number, "spot":c_index}/>
<#assign order_list = order_list + [one_index_obj]/>
</#list><#list order_list?sort_by("count")?reverse as list_item>
${list_item.count}:${list_item.spot}<p>
${boards.board[list_item.spot].title}<p>
</#list>Thanks Yuri, this has been a massive help