ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Conditional to look for open entries?

January 22, 2011 9:56pm

Subscribe [3]
  • #1 / Jan 22, 2011 9:56pm

    roryrabbitfield

    320 posts

    I need a conditional that will look in a channel to see if any entries are status=open or not. Like this:

    {if "a certain channel has any open entries"}Display this static text{/if}

    I don’t know if this can be done, or how. The text I want to display is a link to a channel, and should only appear if there are open entries. But I am not displaying entry fields in there, just this static link.

  • #2 / Jan 22, 2011 10:13pm

    Kevin Cupp

    791 posts

    I’ve done this to do something similar:

    {exp:channel:entries
        channel="articles"
        status="open"
    }
    {if count == 1}Yes there are open entries{/if}
    {/exp:channel:entries}

    But it may be more efficient to use the query module, like this:

    {exp:query sql="SELECT status FROM exp_channel_titles WHERE status = 'open' LIMIT 1"}
    Yes there are open entries.
    {/exp:query}
  • #3 / Jan 22, 2011 10:46pm

    Kevin Cupp

    791 posts

    Oops, be sure to include the channel ID in the query if you go with the second approach.

  • #4 / Jan 22, 2011 10:48pm

    roryrabbitfield

    320 posts

    Ah, that first approach looks like what I need. Perfect. Now my client doesn’t need to ask me to edit the nav bar template if she decides to take a channel of her site offline. Yippie! Thanks a bunch.

  • #5 / Jan 24, 2011 2:48am

    John Henry Donovan

    12339 posts

    Glad Kevin was able to help. Feel free to start a new thread if you have any more questions.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases