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.

show alternate channel based on no_results

August 16, 2012 6:40am

Subscribe [2]
  • #1 / Aug 16, 2012 6:40am

    bikuta

    118 posts

    Hi,

    I have two channels: programs and events.
    Each channel entry has a status and I want to show a program or event with a status of “featured”, but if there are none, I want to show any random program with a status of “open”.

    This is how I tried to do it:

    {exp:channel:entries channel="programs|events" status="featured" limit="1" orderby="random"}
       {if channel == "Programs"}
       <a href="http://{url_title_path=programs}">   _    {if featured_image}_     {featured_image}_    {/if}_    <span class="featured_title"><span>{title}</span></span>_    <span class="featured_summary">{one_liner}…»</span> _   </a>
       {/if}
       {if channel == "Events"}
       <a href="http://{url_title_path=events}">   _    {if event_featured_image}_     {event_featured_image}_    {/if}_   </a>
       {/if}
       {if no_results}
        {exp:channel:entries channel="programs" status="open" limit="1" orderby="random"}
         <a href="http://{url_title_path=programs}">   _      {if featured_image}_       {featured_image}       _      {/if}_      <span class="featured_title"><span>{title}</span></span>_      <span class="featured_summary">{one_liner}…»</span> _     </a>
        {/exp:channel:entries}
       {/if}
      {/exp:channel:entries}

    The {if no_results} section doesn’t seem to work properly. I’m guessing it’s something about having a nested channel entries tag?
    What’s the best way to do this?

     

  • #2 / Aug 16, 2012 11:35am

    John St-Amand

    865 posts

    Yeah, I’m afraid you can’t nest the channel entries loop - at least not in the same “pass”.  You could use an embed for the nested entries loop, but you take a performance hit in so doing.  But in a nutshell, that would do it.  Otherwise you may need to use a custom query to do the lookup and determine what to display.

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

ExpressionEngine News!

#eecms, #events, #releases