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.

Checking if channel entries exist

November 14, 2012 7:19pm

Subscribe [2]
  • #1 / Nov 14, 2012 7:19pm

    kippbrady

    3 posts

    Is it possible to check whether channel entries exist. Something like the following?

    {if channel entries}
     <h1>Results</h1>
     <ul>
      <li>{title}</li>
     </ul>
    {if:else}
     Sorry No Results
    {/if}

    Thanks

     

  • #2 / Nov 14, 2012 8:09pm

    Bhashkar Yadav

    727 posts

    Hi Kippbrady,

    There isn’t any tag like that. Why don’t you use channel:entries tag for the same purpose.


    Best Regards,

  • #3 / Nov 14, 2012 8:18pm

    John St-Amand

    865 posts

    To follow up on what Bhashkar suggested - the channel entries loop will natively not return anything if the channel doesn’t contain any entries based on what your loop’s parameters call for, so effectively the channel entries loop already does what you are looking for.  Based on what you indicated you wanted, you would have a simple structure such as:

    {exp:channel:entries channel="channel_name" orderby="date" sort="desc" disable="whatever|you|don't|need" dynamic="no"}
    {if no_results}
    Sorry No Results
    {/if}
    
    {if count == "1"}<h1>Results</h1>
    <ul>{/if}
    <li>{title}</li>
    {if count == total_results} </ul>{/if}
    
    {/exp:channel:entries}

    Note I simply wrapped your title and the opening of the unordered list with a conditional that would present it only prior to the first entry returned by the loop, and likewise closed the unordered list only after the last entry returned by the loop.  Other that that, the loop would return only a title per entry, wrapped with <li></li>.

  • #4 / Nov 14, 2012 8:29pm

    Bhashkar Yadav

    727 posts

    Thanks John,

    Thanks for elaborating.

  • #5 / Nov 15, 2012 4:41am

    kippbrady

    3 posts

    Thanks for the replies. The above code was meant to be pseudocode for what I’m trying to achieve.

    Forgive I’m coming over from Wordpress and I’m trying to replicate the way I’d do things in that.

    Thanks again.

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

ExpressionEngine News!

#eecms, #events, #releases