No Results
Posted: 11 September 2007 04:32 PM   [ Ignore ]
Newbie
Rank
Total Posts:  4
Joined  2007-06-29

Hi:

Maybe I’m overlooking something obvious?

I have the following code which works except that the header “Related Pages” and the ul tags are displayed even when no results are returned. Ideally I would like the entire “Related Pages” block to be gone and some alternative text to be displayed if there are no results. If I put the header inside the loop then it is displayed for every entry.

<h2>Related Pages</h2>
 <
ul>
{exp:tag:related_entries dynamic="off" limit="10" rank_method "clicks|total_entries"}
{if no_results}
<h2>Some Other Content</h2>
<
p>Lorem Ipsum</p>
{/if}
<li><a href="{comment_url_title_auto_path}">{title}</a></li>
{/exp:tag:related_entries} 
 
</ul>

I would rather do something like this:

{if related_entries}
<h2>Related Pages</h2>
 <
ul>
{exp:tag:related_entries dynamic="off" limit="10" rank_method "clicks|total_entries"}
<li><a href="{comment_url_title_auto_path}">{title}</a></li>
{/exp:tag:related_entries} 
 
</ul>
{if:else}
<h2>Some Other Content</h2>
<
p>Lorem Ipsum</p>
{/if}

Is something like this possible?

jerry

Profile
 
 
Posted: 12 September 2007 06:54 AM   [ Ignore ]   [ # 1 ]
Newbie
Rank
Total Posts:  23
Joined  2006-10-09

Generally, I wrap my headers in a {if count == 1} {/if} statement. You could always try it like this:

{exp:tag:related_entries dynamic="off" limit="10" rank_method "clicks|total_entries"}
{if no_results}
<h2>Some Other Content</h2>
<
p>Lorem Ipsum</p>
{/if}

{if count 
== 1}
<h2>Related Pages</h2>
<
ul>
{/if}
<li><a href="{comment_url_title_auto_path}">{title}</a></li>
{if count == total_results}
</ul>
{/if}
{
/exp:tag:related_entries}

That way it doesn’t loop the header or footer, but only displays them when they are necessary.

Profile
 
 
Posted: 13 September 2007 02:42 PM   [ Ignore ]   [ # 2 ]
Newbie
Rank
Total Posts:  4
Joined  2007-06-29

Scarletboi:

Sweet!! That works perfectly. Thanks.

jerry

Profile