Return list of files without images if fewer than five files

I have a client who is using the option to display a gallery of images on items/show, but wants to display thumbnails of files attached only if there are fewer than five files attached to the item.

How do you return just a list of files (with links to the files themselves) instead of a set of images for the files?

I’m afraid title and text of your post do not match. Which one do you want, thumbnails or not for fewer than 5 Items?

Oh dear–sorry. If there are MORE than five files, it should be a list. Five or less, then the standard image gallery.

In case anyone else is looking to do something similar, this is how I fulfilled this request. I’m sure there are more elegant ways of doing it–feel free to chip in if you have a suggestion–but this worked.

It could be adapted to count just PDFs instead of all files, too. But in the end that wasn’t necessary.

In the theme’s show.php:

<div class="element-text item-file-gallery">
	<?php
		// get a count of all the files attached to the item
		$filesCount = count($item->Files);
		// if there are more than 5 files, display them as a list with text links
		 if ($filesCount > 5) {
			echo '<ul class="file_list">';
			foreach ($item->Files as $file) {
    				echo '<li>';
				echo '<a href="[base url]/files/original/' . $file['filename'] . '" target="_blank">' . $file['original_filename'] . '</a>';
				echo '</li>';
			}
			echo '</ul>';
		} else {
			// if there are 5 or fewer files, display the standard image gallery
			echo files_for_item(array('imageSize' => 'fullsize')); 
		}
	?>
</div>

I meant to write a similar suggestion here, but I lost track of your post. Counting $item->Files is the way I’d go, as you’ve done here.

I think the only thing I’d add is that when you have a $file object, you can get the URL more easily without having to write your site’s base URL in the theme: you can call $file->getWebPath('original') (or metadata($file, 'uri') will give you the same thing and also HTML-escape it for you).

There’s also, if you’re looking more to use thumbnails than text, a function item_image_gallery that will just output the thumbnails as links.