How can I use a condition to check if a channel has any records?

I have a Conditional external channel entry tag that should determine if the channel has 1. Entries in general, 2. Expired entries, 3. Closed entries: I tried {if channel_short_name == "news"} But for some reason this returns wrapped content regardless of whether records are closed or expired. The reason I have a condition that is outside the channel tag is because I don't want to repeat the h2 tag.

 {if there are a displayable entries in the "news" channel, display this whole package.} <h2>News</h2> <hr /> {exp:channel:entries channel="news" limit="2"} <div class="entry panel"> <h3>{title}</h3> {news_text} {if news_full OR news_bild} <div id="{entry_id}" class="toggleDiv"> {news_full} {exp:ce_img:single src="{news_bild}" max_width="346" smart_scale="yes" alt="{name_orig}"} </div> <p><a class="show_hide" rel="#{entry_id}" href="#">Mehr…</a></p> {/if} </div> {/exp:channel:entries} {/if} 

This brings me to another question:

Is it possible to set outdated entries to "private"?

+4
source share
2 answers

The easiest option is to move the header layout to a conditional one, which is displayed only with the first record. If there are no results, the tag {exp:channel:entries} will not generate a result.

 {exp:channel:entries channel="news" limit="2"} {if count == '1'} <h2>News</h2> <hr /> {/if} <div class="entry panel"> <h3>{title}</h3> {news_text} {if news_full OR news_bild} <div id="{entry_id}" class="toggleDiv"> {news_full} {exp:ce_img:single src="{news_bild}" max_width="346" smart_scale="yes" alt="{name_orig}"} </div> <p><a class="show_hide" rel="#{entry_id}" href="#">Mehr…</a></p> {/if} </div> {/exp:channel:entries} 

Is there any special reason why you want to close expired records? If you do not use show_expired = 'yes' , all expired entries will behave as if they were closed anyway.

+8
source

And if you need conditional markup at the end of your loop, you can do {if count == total_results} .

+2
source

Source: https://habr.com/ru/post/1443660/


All Articles