2

Pretty new to ExpressionEngine, so please excuse my lack of knowledge. I have a site where I want to use a slider on pages with more than one article image. The way I have it set up now works fine for these pages, but if there is a page with only 1 image, the image doesn't display because it's being hidden behind and off to the side of the content as if it were a slider image.

Basically, I want to make it so that if there is more than 1 image on the page, it will place the image code inside the "news_slider" div, but if there is only 1 image, it will just place that single image link without a div container. Here's the code:

{if article_images}
   <div id='news_slider'>
      {article_images}
         <img title="{img_title}" src="{img}" />
      {/article_images}
   </div>
{/if}

Thanks in advance!

4

Perhaps there is a more elegant way, but this works:

{article_images}
    {if total_rows > "1" && row_count == "1"}
        <div id='news_slider'>
    {/if}
         <img title="{img_title}" src="{img}" />
    {if total_rows > "1" && row_count == total_rows}
        </div>
    {/if}
{/article_images}
| improve this answer | |
  • 2
    This is what I was slowly typing on an iPad. :) But minus the opening {if articles_images} condition. That's not needed. Just {article_images} tag pair wrapper. If it's empty it won't print anything. – Stephen Callender Nov 6 '13 at 22:10
  • Ha ha, I wondered why you hadn't already nailed it, Stephen. You were encumbered! Max was actually typing at the same time, too. Good point about the outer conditional. I removed that. – Alex Kendrick Nov 6 '13 at 22:11
  • 3
    Dang iPad! :) I get an assist. – Stephen Callender Nov 6 '13 at 22:11
  • Bingo! That worked a treat, thanks to everyone for your efforts! – APAD1 Nov 6 '13 at 22:14
1

With Matrix you can try next code:

{if article_images}
   {if {article_images_total_rows} > 1}<div id='news_slider'>{/if}
      {article_images}
         <img title="{img_title}" src="{img}" />
      {/article_images}
    {if {article_images_total_rows} > 1}</div>{/if}
{/if}
| 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.