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 check if channel has entries, how to do?

December 07, 2011 10:22am

Subscribe [2]
  • #1 / Dec 07, 2011 10:22am

    TGP

    78 posts

    This is the code I have in my template. I want to use a conditional to check if there are any entries in the “events” channel. If there isn’t any entries I want to display a paragraph with some text instead of the unordered list. How would I do this?

    <h2>Upcoming Events</h2>
    <p>    <ul><br />
        {exp:channel:entries channel="events" disable="categories|member_data" dynamic="off" limit="3" show_future_entries="yes" sort="asc"}<br />
         <li><br />
         <time class="time_style">{entry_date format="%F %j %Y"}</time><br />
         <h1><a href="http://{title_permalink=events/details}">{title}</a></h1><br />
         </li><br />
        {/exp:channel:entries}<br />
        </ul>

  • #2 / Dec 07, 2011 12:39pm

    Rob Sanchez

    335 posts

    You could do it like this:

    <h2>Upcoming Events</h2>
    <p>    {exp:channel:entries channel="events" disable="categories|member_data" dynamic="off" limit="3" show_future_entries="yes" sort="asc"}<br />
        {if no_results}<br />
        There are no results.<br />
        {/if}<br />
        {if count == 1}<br />
        <ul><br />
        {/if}<br />
         <li><br />
         <time class="time_style">{entry_date format="%F %j %Y"}</time><br />
         <h1><a href="http://{title_permalink=events/details}">{title}</a></h1><br />
         </li><br />
        {if count == total_results}<br />
        </ul> <br />
        {/if}<br />
        {/exp:channel:entries}

  • #3 / Dec 07, 2011 12:52pm

    TGP

    78 posts

    Thanks Rob, no_results is what I’ve been looking for. I knew there was something, but couldn’t find it.

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

ExpressionEngine News!

#eecms, #events, #releases