0

How do i display the latest entry only that meets the criteria?

Overview:

I have a channel called new. Within that channel there are two fields. File_upload = where you can upload a file. Pull down menu field with an option called "Hero Image"

Desired:

I would like to go through the entire channel and display only the first item that meets the criteria of having a file uploaded and pull down menu selected as "Hero Image"

{exp:channel:entries channel="new"}
    {if file_upload != '' && newType == 'Hero Image'}
        <a href="{new_external_link}"><img src="{file_upload}" alt="{title}" title="{title}" border="0" width=980px></a><br>
    {/if}
{/exp:channel:entries}

1 Answer 1

1

Two things I suggest you might do:

  1. Simplify the {if} loop by using the Channel Entries 'search' parameter
  2. Use the Channel Entries 'limit' parameter to only return the first entry that matches your search conditions.

The resulting code will look something like this:

{exp:channel:entries 
    channel="new" 
    limit="1" 
    search:file_upload="not IS_EMPTY" 
    search:newType='Hero Image'}
        <a href="{new_external_link}">
            <img src="{file_upload}" alt="{title}" title="{title}" border="0" width=980px>
        </a>
        <br>
{/exp:channel:entries}

The only thing I'm not sure about is whether having a space in the newType field will cause problems. It's probably OK, but if you do have problems I suggest you try again after changing the value to be single-words only.

More on channel entries search terms here

HTH

1
  • thanks for the solution and the reference greatly appreciated.
    – Lacer
    Nov 21, 2016 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.