Forum Discussion

bhupen's avatar
bhupen
Advisor
10 years ago

Do not show the post if there is no post

Hi guys. I need some quick help. I have following code.

 

Requirement:

If There is no post then this div should not be visible in front end also same with View all Link:

 

<div class="clearfix two-latest-post">
    
            <#assign messages = rest("2.0","/search?q=" + "SELECT * FROM messages WHERE author.id='${user.id}' 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>
                    <br/>
                    <a href="abc.com"><strong>See more Recent Posts</strong></a>
                </div>

 

  • bhupen - Below is the working code. You need to check the size of the result.

     

    <#setting url_escaping_charset='ISO-8859-1'>
    <div class="clearfix two-latest-post">
    <#assign messages = rest("2.0","/search?q=" + "SELECT * FROM messages WHERE author.id='${user.id}' ORDER BY post_time DESC LIMIT 5"?url) />
    		
    		<#list messages.data.items as recent >
    			<#if recent?has_content>
    				<a href="${recent.view_href}">${recent.subject}</a><br/>
    			</#if>   
    			
    		</#list>
    		<br/>
    	<#if messages.data.size &gt; 0> <!-- check the size of the response-->
    		<a href="abc.com"><strong>See more Recent Posts</strong></a>
    	</#if>
    </div>

     

  • bhupen - Below is the working code. You need to check the size of the result.

     

    <#setting url_escaping_charset='ISO-8859-1'>
    <div class="clearfix two-latest-post">
    <#assign messages = rest("2.0","/search?q=" + "SELECT * FROM messages WHERE author.id='${user.id}' ORDER BY post_time DESC LIMIT 5"?url) />
    		
    		<#list messages.data.items as recent >
    			<#if recent?has_content>
    				<a href="${recent.view_href}">${recent.subject}</a><br/>
    			</#if>   
    			
    		</#list>
    		<br/>
    	<#if messages.data.size &gt; 0> <!-- check the size of the response-->
    		<a href="abc.com"><strong>See more Recent Posts</strong></a>
    	</#if>
    </div>

     

    • bhupen's avatar
      bhupen
      Advisor

      VarunGrazitti  your code works with "View All links" but it doesn't work with post:

       

      I want to show "No Post Found" if there is no post:

      <#assign messages = rest("2.0","/search?q=" + "SELECT * FROM messages WHERE author.id='${user.id}' ORDER BY post_time DESC LIMIT 5"?url) />
      		
      		<#list messages.data.size &lt; 0>
      			<#if recent>
      				<a href="${recent.view_href}">${recent.subject}</a><br/>
      <#else>
      No Post found </#if> </#list> <br/> <#if messages.data.size &gt; 0> <!-- check the size of the response--> <a href="abc.com"><strong>See more Recent Posts</strong></a> </#if> </div>
      • bhupen - Try this one

         

        <#setting url_escaping_charset='ISO-8859-1'>
        <div class="clearfix two-latest-post">
        <#assign messages = rest("2.0","/search?q=" + "SELECT * FROM messages WHERE author.id='${user.id}' ORDER BY post_time DESC LIMIT 5"?url) />
        	<#if messages.data.size &gt; 0> <!-- check the size of the response-->
        		<#list messages.data.items as recent >
        			<#if recent?has_content>
        				<a href="${recent.view_href}">${recent.subject}</a><br/>
        			</#if>   
        			
        		</#list>
        		<br/>
        	
        		<a href="abc.com"><strong>See more Recent Posts</strong></a>
        	<#else>	
        		No Posts Found
        	</#if>
        </div>