Forum Discussion

Mach008's avatar
Mach008
Guide
7 years ago

Moving lastest post date to category banner

Hello everyone,

This is what I am trying to do on the category tabs:

  • Category Title
  • Post Counts
  • Post_date (just one from the latest posts from any of the boards)

This is what I have so far with the title and counts working except the date:

<--!

<#assign categories = rest("/categories").categories />

<#assign threadCount = (rest(category.@href + "/topics/count").value)?number />

<#assign postTime = (rest(category.@href + "/messages/post_time").value)/>

Thank you in advance I appreciate it any direction or help on this topic.

 -->

  • Mach008

    You can use context object to get the category title on the category page.  Context object will give the error in the component but works fine on community pages i.e. Category page, board page etc. 

    Here is the code to get the title and threads count on the category page you are visiting

    <#assign title = ${coreNode.id} />
    <#assign threadCount = (rest(/categories/id/${coreNode.id}/topics/count").value)?number />

    V1 API does not allow to fetch the partial info. I mean you can not get only post_time from the message, it would return the whole message content. 

    For this one, you have to use the V2 API

    select post_time from messages where category.id="${coreNode.id}" order by post_time desc

     

3 Replies

  • Mach008

    You can use context object to get the category title on the category page.  Context object will give the error in the component but works fine on community pages i.e. Category page, board page etc. 

    Here is the code to get the title and threads count on the category page you are visiting

    <#assign title = ${coreNode.id} />
    <#assign threadCount = (rest(/categories/id/${coreNode.id}/topics/count").value)?number />

    V1 API does not allow to fetch the partial info. I mean you can not get only post_time from the message, it would return the whole message content. 

    For this one, you have to use the V2 API

    select post_time from messages where category.id="${coreNode.id}" order by post_time desc

     

  • Mach008's avatar
    Mach008
    Guide
    7 years ago

    Hey VikasB,

    Thanks again for help on this, but I'm still having trouble implementing this on our community. Our goal is to create an accordion on the main community page and I am stuck on the post time part.

    This is what I have so far:

    <#macro display_category_node category disabled=false>
    <#assign threadCount = (rest(category.@href + "/topics/count").value)?number />
    <#assign tTime = rest("2.0","/search?q=" + "select post_time from messages where category.id="${category.title}" order by post_time desc”?url) />

    <div class="category-node-wrapper category-node-${(utils.css.toValidClassName(category.id))!""}">

    <div class="category-title">
    ${(category.title)!""}
    <span class="cat-thread-count">(${threadCount?string(",##0")})</span>
    <#list tTime.data.items as recent >
    <span class="cat-post-time”>${recent.post_time?datetime}
    </span>

    </div>

    </div>
    <div class="custom-board-browser">
    <ul class="custom-board-list">
    <#list rest(category.@href + "/boards/nested").boards.board as board>
    <li class="custom-board-list-item">
    <@display_board_node board />
    </li>
    </#list>
    </ul>
    </div>

    </div>

     

    I appreciate any help on this issue.

     

    Thank you