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.

If no entries in one section... show an entry from another section..

October 31, 2011 4:31pm

Subscribe [3]
  • #1 / Oct 31, 2011 4:31pm

    Etheya

    213 posts

    Hi all..

    As the title says, im basically wanting to put some code together to basically check one channel for an open entry.. if there is no entry for this channel, then i want to show an entry from another channel..

    Tried a few variations with the {no_results} tag but to no avail…

    How best can i do this?

    Its as simple as i want to show a competition if there is one, if not i want to show an entry from another channel..

    Sounds simple.. but cant quite get it to work…

  • #2 / Nov 01, 2011 6:43am

    Mark Bowen

    12637 posts

    Hi Brian,

    Not seeing what you’ve tried I can’t say why it’s not working but you could perhaps do something like this maybe?

    Main Entries Tag

    {exp:channel:entries
     channel="main_channel"
     limit="1"
     dynamic="no"
     search:body="asdasdasdasdasd"}
    
    {if no_results}
    {embed="template_group/no_results_tag"}
    {/if}
    
    {title}
    
    
    {/exp:channel:entries}

    template_group/no_results_tag

    {exp:channel:entries
     channel="no_results_channel"
     dynamic="no"}
    
    {title}
    
    
    {/exp:channel:entries}

    I placed the search:body=”“ parameter in the first tag just to ensure I didn’t get any results for testing purposes but obviously use whatever tag parameters you need there.

    Upon getting no results I’m using the {embed} variable to bring back a secondary tag instead.

    Hope that helps a bit.

    Mark

  • #3 / Nov 01, 2011 7:17am

    Etheya

    213 posts

    Hi Mark..

    Sorry brain not in gear.. i didnt put the other {exp:channel:entries} into an embed.. thats why! duh!

    Im sure that will work now..

  • #4 / Nov 01, 2011 10:51am

    Sue Crocker

    26054 posts

    Thanks for the assist, Mark!

    Etheya - going to go ahead and close this thread. 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