Forum Discussion

bhupen's avatar
bhupen
Advisor
10 years ago

How to show only 5 posts?

Hi guys,   I need to show only 5 posts. Somehow I am able to show the latest posts but My query is not working to show up only 5 posts: Following is the code I have done:   <#list restadmin("/ro...
  • OlivierS's avatar
    OlivierS
    10 years ago

    bhupen 

     

    You can mix API v1 and API v2 calls.

    If you want to optimize the code, have a look at the User resource in the API v2 documentation and check if you can get the favourite.

     

    Here is the code that should work. You need to provide a valide user.id for your rest call.

    It will loop the user favourite and build a list for the WHERE CLAUSE used to get the last 5 messages.

     

    <h3>Latest Posts from Favorites Users</h3> <br />
    <#assign whereclause = ""/>
    <#list restadmin("/users/id/${user.id}/addressbook/contacts/friends").users.user as user>
    <#if user??>
    <#assign whereclause = whereclause + "'" + user.id + "'" />
    <#if user_has_next><#assign whereclause = whereclause + "," /></#if>
    </#if>
    </#list>

    <#if wherclause??>
    <#assign messages = rest("2.0","/search?q=" + "SELECT subject, view_href, post_time_friendly, board.id, author.id FROM messages WHERE author.id IN (${whereclause}) ORDER BY post_time DESC LIMIT 5"?url) />


    <#list messages.data.items as recent >
    <#if recent??>
    <a href="${recent.view_href}">${recent.subject}</a><br/>
    </#if>
    </#list>
    </#if>