Forum Discussion

bhupen's avatar
bhupen
Advisor
10 years ago

How to display Favorited Users 5 Latest Post

Hi guyz,   Favorited Users 5 Latest Posts (previously known as 'Friends') with a link to follow through to the respective threads. In short how can I display favourite user latest post? Any API a...
  • bhupen's avatar
    10 years ago

    Hi guyz I got the solution for this requirement. Hope this may help someone else:


    <h3>Latest Posts from Favorites/Friends 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 whereclause??>
    <#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) />
    <#if messages.data.items??>
    <#list messages.data.items as recent >
    <#if recent??>
    <a href="${recent.view_href}">${recent.subject}</a><br/>
    </#if>
    </#list>
    </#if>

    Note: If you will direct fetch the requirement using rest api then you can't show only 5 post. For that you have to use API V2. Like I did in above example.

     

    Cheers!