1

I've got a situation where I'm pulling a list of channel entries, each of which link to a page with more details. The channel is called "audio", and it contains a Channel Files field that can hold multiple audio files.

What I would like to do is this:

  • If the entry contains just one audio file, do ABC.
  • If the entry contains more than one audio file, do XYZ

Here is my "dumbed-down" code

{exp:channel:entries channel="teleconferences"}
    {exp:channel_files:files entry_id="{entry_id}" limit="1"}
        <p><a href="/{segment_1}/{url_title}">Full Details</a></p>
    {/exp:channel_files:files}
{/exp:channel_files:files}

If I don't put a limit on the {exp:channel:entries" tag, then it prints a link for the total number of files in the entry. So if there were 5 files in Entry A, and 1 in Entry B, it would look like this:

  • Entry A
  • Entry A
  • Entry A
  • Entry A
  • Entry A
  • Entry B

If I do put a limit, then I get that number per page, with pagination.

If I add a limit to the {exp:channel_files:files} tag, then I only get one entry, but I'm unable to do ABC or XYZ on it. Basically, what I'd like to do is put a play button if there is only one audio file, or a link to the page if there are multiple audio files.

Perhaps this isn't doable but I thought I would ask the experts!!

1

Try this.

{exp:channel:entries channel="teleconferences"}
    {exp:channel_files:files entry_id="{entry_id}"}
        {if file:count==1}
           /// do ABC ///
        {if:else}
           /// do XYZ ///
        {/if}
    {/exp:channel_files:files}
{/exp:channel:entries}

Don't forget to remove the limit from {exp:channel_files:files}

Oh. And your closing tag should read {/exp:channel:entries}

| improve this answer | |
  • Thanks Steve. I'm getting the "do this or do that" based on the count. However, it still creates a line item for each of the number of files that the entry contains (Entry A, Entry A, Entry A, Entry A, Entry A, Entry B). And the first line item for Entry A is the same as Entry B (doing ABC) while the rest of the line items for Entry A are doing XYZ. – Todd Feb 28 '15 at 0:01
0

OK, I had made it way more complicated than it needed to be, and I really wasn't coding it right. Here is what I ended up doing:

    {exp:channel:entries channel="teleconferences"}
    <tr>
      <td>
        {exp:channel_files:files entry_id="{entry_id}"}
            {if file:total == 1}
            --- Put a play button here ---
            {/if}
        {/exp:channel_files:files}
      </td>
      <td>The rest of my code</td>
   </tr>
   {/exp:channel:entries}

This works exactly as I had hoped!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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