How to anchor text of link to item files?

68 views
Skip to first unread message

Jeanne

unread,
Sep 19, 2009, 12:25:50 AM9/19/09
to Omeka Dev
I want to use an item's file's title as the anchor text to that file.

See this example: http://caseyfeldman.com/items/show/52

Rather than displaying:
Click to view file: GSR_Newsletter_SUMMER.pdf

I would like the anchor text to be what I entered in the file's Core
Metadata Title instead of the files' filename.

Is there any way to do this?

Thanks!
Jeanne

Jeremy Boggs

unread,
Sep 19, 2009, 11:06:09 AM9/19/09
to omek...@googlegroups.com

There is a way to do this, but you have to forgo using the
display_files_for_item() helper and write out a custom loop of files.
We could probably make this an option in that helper in a future
release. In the meantime, here's one example of what you could do in
your items/show.php template:

<?php foreach($item->Files as $file): ?>

<a href="<?php echo file_download_uri($file); ?>"><?php echo
item_file('Dublin Core', 'Title', array(), $file); ?></a>

<?php endforeach; ?>

This gets the array of $item->Files, and loops through each. It uses
the file_download_uri() helper to get the path of the file to
download, and sets that as the value for the HREF attribute. It also
uses the item_file() helper to get metadata for a file, and adds that
as the text inside the <a> tag.

This, of course, would use the same markup for all files, regardless
of type, so it wouldn't show thumbnails or embed videos. If you need
to account for different ways to display different types of files,
that can be done too.

Hope this helps!
Jeremy

Jeanne

unread,
Sep 19, 2009, 6:25:38 PM9/19/09
to Omeka Dev
Thanks.. this looks like just what I was looking for.
Is file_download_uri($file); documented someplace I didn't find?

Jeanne

Jeremy Boggs

unread,
Sep 20, 2009, 12:00:51 PM9/20/09
to omek...@googlegroups.com
On Sep 19, 11:06 am, Jeremy Boggs <jer...@clioweb.org> wrote:
> <?php foreach($item->Files as $file): ?>
>
> <a href="<?php echo file_download_uri($file); ?>"><?php echo
> item_file('Dublin Core', 'Title', array(), $file); ?></a>
>
> <?php endforeach; ?>


Actually, looking at this more, it would be better to use the
loop_files_for_item helper instead of using the $item->Files array
directly. The first example I gave you works fine, but this one uses a
bit less code, and doesn't require you to send all the options to the
item_file() helper:

<?php while(loop_files_for_item()): ?>

<a href="<?php echo file_download_uri($file); ?>"><?php echo

item_file('Dublin Core', 'Title'); ?></a>

<?php endwhile; ?>

The loop_files_for_item() helper is documented (http://omeka.org/codex/Theme_API/loop_files_for_item
), but the example doesn't use the item_file() helper to retrieve
metadata about a file. I'll be sure to update that when I get a chance.

On Sep 19, 2009, at 6:25 PM, Jeanne wrote:
> Thanks.. this looks like just what I was looking for.
> Is file_download_uri($file); documented someplace I didn't find?

That helper isn't documented; in fact, its not even listed on the
Theme API page. It will basically give you the web path for a given
file in your archive directory. We can add that to the list, though.

Best,
Jeremy

Jeanne

unread,
Sep 20, 2009, 8:27:12 PM9/20/09
to Omeka Dev
Okay... a couple of new related questions:

1) is there a way to code this so that if there is no Title entered,
that you default to using the file's filename? right now if there is
no filename entered - we get no link at all

2) This next question is going to sound sort of 'meta' - but is there
a way to show an image that links to let you download a file other
than the image itself? A little context might help -- we have PDFs of
news articles and we want to add each as an item. Right now we end up
with a very sparse page for the item with a link to read the PDF (see
example here: http://www.caseyfeldmanmemories.org/items/show/59 ).
What I am imagining would be nice would be to show an image of the
first page of the PDF which when you clicked upon it would actually
download the PDF itself. Basically I want a thumbnail related to an
uploaded file.

Thanks!
Jeanne

Dave Lester

unread,
Sep 22, 2009, 8:58:46 AM9/22/09
to Omeka Dev
Hi Jeanne,

1) When you upload a file into Omeka, it tries to create derivative
images (fullsize, thumbnail, square thumbnail). If Omeka successfully
creates derivatives, then the display of a file (on an items/show/
page) in a theme defaults to displaying a square thumbnail of the
first file, and the filenames of any additional files. The filename
that's displayed by default is the original filename that was used to
upload, so there should never be a circumstance where there's filename
entered.

Could you give an example of where this is occurring?

2) Right now thumbnails are not created for PDF files upon upload. I
believe the problem relates to Ghostscript, which is required for such
processing, and which is something that many shared hosts (including
Dreamhost) do not support.

While Omeka doesn't automatically create derivative images of PDF
files, it can display icons for specific mime-types if that's of
interest at all. You'll specify the mime-type, and the location of a
thumbnail in your theme. If for example you had an icon (pdf.png) for
a PDF file in the images folder of your current theme, you could use
the following code:

<?php

echo display_files_for_item(array('showFilename'=>false,
'linkToFile'=>true, 'icons' => array('application/pdf'=>img
('pdf.png'))));

?>

Dave
Reply all
Reply to author
Forward
0 new messages