Myko_P
7 years agoExpert
A custom component that shows 3 last posts selected from all the community blogs
Hi,
I am trying to build custom component/widget for the main page. The idea is to show our users in a visual manner 3 last posts selected from all the community blogs.
Selected blog posts should be sorted by the time of publication in descending order. I want also to show the post subject, post cover image, link to the post, post time, post author's nickname and avatar for each of the 3 selected blog posts.
Could you please take a look at my code below:
<#-- SELECTS DATA AND ASSIGNING VARIABLES --> <#assign messageId = rest("2.0","/search?q=" + "SELECT id FROM messages WHERE board.id in ('Help', 'Blogs') AND depth = 0 ORDER BY post_time DESC LIMIT 3"?url).data.items /> <#assign subject1 = rest("/messages/id/${messageId[1].id}") /> <#assign subject2 = rest("/messages/id/${messageId[2].id}") /> <#assign subject2 = rest("/messages/id/${messageId[3].id}") /> <#assign cover1 = rest("messages/id/${messageId[1].id}/images") /> <#assign cover2 = rest("messages/id/${messageId[2].id}/images") /> <#assign cover3 = rest("messages/id/${messageId[3].id}/images") /> <#assign link1 = rest("/messages/id/${messageId[1].id}?restapi.response_style=view") /> <#assign link2 = rest("/messages/id/${messageId[2].id}?restapi.response_style=view") /> <#assign link3 = rest("/messages/id/${messageId[3].id}?restapi.response_style=view") /> <#assign post_time1 = rest("/messages/id/${messageId[1].id}?restapi.response_style=view") /> <#assign post_time2 = rest("/messages/id/${messageId[2].id}?restapi.response_style=view") /> <#assign post_time2 = rest("/messages/id/${messageId[3].id}?restapi.response_style=view") /> <#assign author1 = rest("/messages/id/${messageId[1].id}?restapi.response_style=view") /> <#assign author2 = rest("/messages/id/${messageId[2].id}?restapi.response_style=view") /> <#assign author3 = rest("/messages/id/${messageId[3].id}?restapi.response_style=view") /> <#-- SHOWS SELECTED DATA ON THE MAIN PAGE --> <#-- Shows Link and subject of the blog message #1 --> <a href="${link1.message.@view_href}">${subject1.message.subject}</a> <#-- Shows Cover Image of the blog post #1 --> <img src="${cover1.images.image.url}"/> <#-- Shows Post time of the blog post #1 --> ${post_time1.message.post_time.@view_date} <#-- Shows Author's avatar of the blog post #1 --> <img src="${author1.userAvatar.image.url}"/> <#-- Shows Author's login of the blog post #1 --> ${autthor1.author.login.@view_date}
PS Is it possible to select from all the community's blogs without addressing every single blog (board) ID?
Thank you!