I was wondering if anyone has a decent trick to show 4 images in a row from multiple entries containing channel images. So the four newest channel-images no matter which entry they come from.

The problem is that I don't know how may images an entry will contain, since you can put any number of images in an entry.


{exp:channel:entries limit="4"}
       <img src="{image:url:large}" />

Will output any number of images, depending on the amount of images in the channel_images_field. It could be 3+2+5+7.

I could of course erase the rest using brute force js frontend or with css overflow:hidden, but I'd rather just parse 4 from the server.


The complete tag is inside a category tag and contains another EE field, making it difficult to use the channel_images tag outside the channel entries tag.

{exp:channel:categories channel="gallery"}
{exp:channel:entries channel="gallery" dynamic="no" category="{category_id}" limit="4"}
        <img src="{image:url:large}" />

I suppose that makes it impossible to really solve it due to nesting issues. It's either all images from a channel, agnostic to the related entries, or the images inside a specified entry tag, agnostic to the channel_images total.

See it live here: http://www.fotografielessen.nl/index.php/Fotoalbum/ (now showing the first four entries with all the images, sorted by category)


The docs seem to suggest you can use the {exp:channel_images:images} tag outside of the channel:entries loop. Have you tried that? So adding the channel, category, limit, orderby and sort parameters.

{exp:channel_images:images channel="<your-channel>" category="<your-category(s)>" limit="4" orderby="upload_date" sort="desc"}
    <!-- Template Code -->

EDIT: Failing that, you could always use a separate channel:entries loop for the images and limit that to 4 entries making sure you've ordered it by entry date. Then within that limit your channel_entries loop to 1 image. This assumes you will always have 1 or more images per channel.

So for your example:

{exp:channel:entries orderby="date" sort="desc" limit="4"}
       {channel_images_field limit="1"} 
       <img src="{image:url:large}" />
  • Thanks Steve, but this will limit the amount of images displayed in each entry, but not for all entries combined. – noregt Aug 20 '13 at 9:44
  • Are you wanting to just show the first 4 images for all of the channel entries combined? It'd probably be worth expanding your question with a bit more information as it's not totally clear at the moment. – Steve Holland Aug 20 '13 at 10:33
  • Sorry if I'm not completely clear on this. Yes, I want to show the first 4 channel images from all entries combined. So the four newest images no matter which entry they come from (restricted to a certain category, but that's something different) – noregt Aug 20 '13 at 10:36
  • The docs seem to suggest you can use the {exp:channel_images:images} tag outside of the channel:entries loop. Have you tried that? So adding the channel, category, limit, orderby and sort parameters. Like I said I've haven't use the addon myself, so apologies if you've already tried this. – Steve Holland Aug 20 '13 at 11:00
  • Steve, your edit was the exact solution that I had. The point is that it only shows the first image per entry. since this is a site for photography students it confused them. But your last comment was right, you can use it outside the the entries tag. Only you then can't combine it with other fields from the entry and the category is not the EE category. So it only shows the last for images from a channel. I'm afraid this ends in a nesting impossibility :-S – noregt Aug 21 '13 at 14:31

To get the most recent 4 images from a channel simply do:

{exp:channel_images:images channel="gallery" limit="4"}
<img src="{image:url}" alt="{image:title}">


  • Hi Brad, you're right that works. I have a different EE field as well that should go with the image (comment of the poster) and it needs to be dynamically limited to a category. I think this answers my question, but only if I show the four latest images from a channel? – noregt Aug 21 '13 at 14:35
{exp:channel:entries channel="channel_name" limit="10"}
        {exp:channel_images:images entry_id="{entry_id}" prefix="nested" limit="4"}

Try that. Basic stuff. Read the docs on channel images.

  • This limits the amount of images in ONE entry, but I want to limit the amount of images in the entries combined. In this scenario I could end up with 40 images (4x10) instead of 4. – noregt Aug 20 '13 at 10:02
  • Ok, missed that. Sorry. Look at the db table for exp_channel_images. You will see each image has an entry_id and upload_date. Using the channel images tag, try limit 4, sort desc, orderby upload_date. But that may/will give you multiple images from one entry. My suggestion, youll need to write a custom plugin with a query to wrap the channel images tag. Your plugin will return an array of 4 entry_ids. – Lloyd Hill Aug 20 '13 at 11:20

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.