Forum Discussion

bhupen's avatar
bhupen
Advisor
10 years ago

Is it possible to show only current day posts?

Hi guyz,

I got latest reply topic but I want to show the only current day's highest reply post?

 

Solution in my mind:

I got the post date, I want to compare post date with current date.  But iam not sure is this good approach or not. Please suggest:

 

<#assign messages = rest("2.0","/search?q=" + "SELECT * FROM messages WHERE replies.count(*)>0 AND depth=0 order by replies.count(*) desc LIMIT 3"?url) />
<#if messages.data.items??>
  <#list messages.data.items as recent >
    <#if recent?has_content>
       <span>${recent.post_time?datetime}</span>
      <br/>
        </#if>
  </#list>
</#if>

 

Query: how can I compare this date with current date.  although we can get current day with ${.now}

Please suggest. Is it possible to make check so that we can show only current highest reply post?

  • OlivierSPaoloT  Thanks for your help.  OlivierS specially thanks for your effort. I have achived it other way. Iam posting it here might be help someone else:

     

    <h3>Trending Post</h3> <br />
    <#assign apiVersion = "2.0"/>
    <#assign today = .now>
    <#assign dateToday = today?string("yyyy-MM-dd'T'HH:mm:ss'+00:00'")  />
        <#assign x= rest(apiVersion,"/search?q=" + "SELECT id, subject,post_time,author, view_href, replies.count(*) FROM messages WHERE
        post_time >= ${dateToday} AND board.id = '10031' AND depth=0 ORDER BY replies.count(*) DESC LIMIT 5"?url) />
        
    <#if x.data.items ?? >
        <#list x.data.items as message >
                <p><a href="${message.view_href}">${message.subject}</a></p>
                <span>${message.author.login}</span>
        </#list>
    </#if>    

    Thanks for your help all.

    Cheers!

  • bhupen - you'll need to create a function for this which will compare the dates for you. An overview is below:

     

    <#assign end_date = .now?long?replace(",","")?substring(0,10)> <!-- Converting current time from millisecs to epoch time-->
    
    <#assign start_date = (end_date?number - 86483)?replace(",","")?substring(0,10)> <!-- 86483 epoch for 1 day-->


    <#assign recent_threads = restadmin("/boards/id/${board_link.id}/search/messages?q=date%3A%5B${start_date}%20TO%20${end_date}%5D&restapi.response_style=view").messages/>

     

     You can then build on this.

    • bhupen's avatar
      bhupen
      Advisor

      VarunGrazitti  I gave a try but it didnt work out for me. Its showing error to me:

      error:

      The following has evaluated to null or missing:
      ==> board_link

       

      Following is the chunk of code i have used:

       

      <#assign messages = rest("2.0","/search?q=" + "SELECT * FROM messages WHERE replies.count(*)>0 AND depth=0 order by replies.count(*) desc LIMIT 3"?url) />
      <#assign end_date = .now?long?replace(",","")?substring(0,10)> <!-- Converting current time from millisecs to epoch time-->
      <#assign start_date = (end_date?number - 86483)?replace(",","")?substring(0,10)> <!-- 86483 epoch for 1 day-->
      <#assign recent_threads = restadmin("/boards/id/${board_link.id}/search/messages?q=date%3A%5B${start_date}%20TO%20${end_date}%5D&has_kudos=${has_kudos}&restapi.response_style=view&page_size=10").messages/>
      <#setting locale="en_US">
      <#if messages.data.items??>
        <#list messages.data.items as recent >
          <#if recent?has_content>
            <a href="${recent.view_href}">${recent_threads.subject}</a>
            <span>${recent_threads.author.login}</span>
            <span>${recent_threads.post_time?datetime}</span>
            <br/>
          <#else>
            No post  found.
          </#if>
        </#list>
      </#if>

       

      also Iam not clear about this:
      %3A%5B${start_date}%20TO%20${end_date}%

       

      will it give me on current day post?

       

      Thanks

       

      • bhupen - it was our piece of code, the board_link is defined in ours, you need to pass the node you're in. Moreover, you seem to have mixed V1 andV2 again, you can but what you were trying to do was you picked data items from V2 but dates were in V1. Below is a code for V1, works fine. You need to pass the node and dates

         

        This will help for dates: http://www.epochconverter.com/

         

        <#assign end_date = .now?long?replace(",","")?substring(0,10)> <!-- Converting current time from millisecs to epoch time-->
        <#assign start_date = (end_date?number - 86483)?replace(",","")?substring(0,10)> <!-- 86483 epoch for 1 day-->
        <#assign recent_threads = restadmin("/boards/id/${YOUR_NODE_ID}/search/messages?q=date%3A%5B1391688278%20TO%201423224278%5D&restapi.response_style=view").messages/>
        <#list recent_threads.message as recent >
        
        <a href="#">${recent.subject}</a><br/>
        </#list>

         

        NOTE: I HAVE HARD CODED DATES IN THE QUERY, please pass it as per your needs using 

         

        /boards/id/${Your_node}/search/messages?q=date%3A%5B${start_date}%20TO%20${end_date}%5D&restapi.response_style=view&page_size=3