Lightbox - pdf files - Omeka 1.2

Would like to avoid having Lightbox go into a loop trying to display a pdf; I tried

$file = get_current_file();
if ($file->hasThumbnail())
 {
echo '<p><em>Click the Image for Full Size</em></p>';
echo display_files_for_item(array('linkAttributes'=>array('rel'=>'lightbox[gallery]')));
}

and it works for jpg's but the fact that the pdf has no thumbnails isn't being detected. There must be some simple method, but for the life of me...

The problem may be with the PDFs since Omeka doesn't create a thumb for them. Lightboxes usually work with images. You can upload an image to the item with the PDF so that an image will represent the item.

Yes, thanks, I have no problems with images and actually did that, but the pdf file is being treated as an image even though there is no thumbnail. Is there a reason the if ($file->hasThumbnail()) condition is always being met, even though there is no thumbnail for that file? It should fall through and do nothing, and allow the linked pdf file in Associated Files to be clicked on and displayed as the pdf. Seems logical to me but...?

I'm not sure, but it seems like you aren't actually looping through all of the files. Is this code wrapped in a loop?

Well, I hope so-- but there's been a lot of experimenting. It's currently:

` <div class="item hentry">
<div class="item-meta">
<?php
while(loop_files_for_item()):
?>
<div class="item-img">
<?php
$file = get_current_file();
if ($file->hasThumbnail())
{
echo '<p>Click the Image for Full Size</p>';
echo display_files_for_item(array('linkAttributes'=>array('rel'=>'lightbox[gallery]')));
}

?>
</div>
<?php endwhile; ?>

</div>

... thinking it should fall right through on the pdf since there's only one jpg and one pdf for that item. Not so??

Oh yeah, sorry -- this is what is generated -

<!-- The following returns all of the files associated with an item.-->
	<div id="itemfiles" class="element">
	    <h3>Files</h3>
		<div class="element-text">
		  <p><em>Click the Image for Full Size</em></p><div class="item-file image-jpeg"><a class="download-file" href="/archives/files/download/42/fullsize" rel="lightbox[gallery]"><img src="/archives/files/display/42/square_thumbnail" class="thumb" alt="Confederate Bond"/>
</a></div><div class="item-file application-pdf"><a class="download-file" href="/archives/files/download/56/fullsize" rel="lightbox[gallery]">confbond-054_2008_149_1.pdf</a></div>
		</div>
	</div>

I think your problem is probably in using display_files_for_item(). This will return all the files, even though you have set the loop. Try replacing that with display_file().

display_file() in this statement breaks the page format... should it go elsewhere?

echo display_files(array('linkAttributes'=>array('rel'=>'lightbox[gallery]')));

That's close. Just a couple things. One you need to reference $file with display_file. And two, just note you have display_files, not display_file (just a typo I'm sure). So I think it should probably look like this:

<?php
    $file = get_current_file();
    if ($file->hasThumbnail()):
    echo display_file($file,array('linkAttributes'=>array('rel'=>'lightbox[gallery]')));
    endif;
?>

It is truly mortifying how simple you make it look!
Works perfectly and I'm as grateful as I am relieved. Thanks.

I'm having the same issue. Lightbox wants to display pdfs that are associated with an item if there's a jpg present as well. Here's the code we're using (recommended from the lightbox install post):

<?php if (item_has_thumbnail())

					{
					echo '<p><em>Click the Image for Full Size</em></p>';
					echo display_files_for_item(array('linkAttributes'=>array('rel'=>'lightbox[gallery]')));
										}
			else
				{
				echo display_files_for_item();
				}
			?>

		<!-- The following returns all of the files associated with an item. -->
	<div id="itemfiles" class="element">
	    <h3>Files</h3>
		<div class="element-text">

		</div>

	</div>

Any suggestions for a fix? The suggested posted above breaks the item show page.

Thanks!

The code posted just above yours was actually a fragment; it's meant to be used in combination with some of the earlier-posted code.

The full code loops over all the files for the item, and checks each one to see if it has a thumbnail. If it does, it adds the lightbox code. If not, it displays the file as normal.

<?php
    while (loop_files_for_item()):
        $file = get_current_file();
        if ($file->hasThumbnail()):
            echo '<p><em>Click the Image for Full Size</em></p>';
            echo display_file($file, array('linkAttributes'=>array('rel'=>'lightbox[gallery]')));
        else:
            echo display_file($file);
        endif;
    endwhile;
?>