4

I have a Conditional Outside a Channel entries tag which should determin if a Channel has 1. Entries at all, 2. Expired entries, 3. Closed entries: I tried {if channel_short_name == "news"} But somehow that returns the wrapped content no matter if entries are closed or expired. The reason that I have the conditional is outside the channel tag is that I dont 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 expired entries to "closed"?

Adrian Macneil
  • 13,017
  • 5
  • 57
  • 70
KSPR
  • 2,212
  • 4
  • 29
  • 46

2 Answers2

8

The simplest option would be to move your header markup into a conditional that is only displayed with the first entry. If there are no results then the {exp:channel:entries} tag will generate no output.

{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 particular reason why you want to close expired entries? Unless you're using show_expired = 'yes' all expired entries will behave as if they're closed anyway.

Dom Stubbs
  • 1,198
  • 7
  • 15
  • 1
    Thank you. I didn't know about this. This is very handy. The reason I'd like them to be closed is because this way you can see in the cp entry list which entry is online and which is not. My client struggles with this. so I tought, just for the sake of backend usability for my client it would be better when they receive the Status "Closed" – KSPR Nov 03 '12 at 13:21
  • I suppose you could setup a cronjob that runs once a day, closing any expired entries. That's pretty hacky though. You might want to try the [Zenbu](http://devot-ee.com/add-ons/zenbu) addon - it would let you setup saved searches which automatically exclude expired entries. I've not used it myself, but I think you can setup permissions on different searches, so you could effectively hide any expired entries from the client. – Dom Stubbs Nov 05 '12 at 10:16
  • Thanks for your answer. I know Zenbu and used it several Times. But I'm a little annoyed that I need to pay 30 bucks for such a basic Functionality. I mean how hard can it be to just ad some icon or text to expired entries in the Backend? CronJob is indeed too hacky :) – KSPR Nov 05 '12 at 15:08
  • I know what you mean, but that's the reality of EE development in 2012, for better or worse. I would love to see various features included in the core (e.g. having to pay for [an addon](http://www.devdemon.com/updater/) to achieve a decent EE/addon upgrade workflow is _insane_) but there's no sign that this will be happening any time soon. – Dom Stubbs Nov 05 '12 at 15:45
2

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

Tyssen
  • 1,569
  • 16
  • 35