Download link for items

Hello everyone,

I´m trying to add a download link for items.
I followed other tutorials regarding this, but I had no luck making it work (I used the Get metadata for a record).

Has anyone manage to add a download link?

Thanks!

Could you clarify what, exactly, you want to download?

Hey Patrick,

I would like to add a download link for Image Files.

I would like to achieve something like this:
http://hist-301.musselmanlibrary.org/peace/omeka/items/show/23

I tried out the information from different forums, but i can’t make it work.

This is how it looks now:
http://andrespardo.digital/badac/document/10

I would appreciate if you can give me a hand with this one.

thanks for your time.

Well, the image as it is now has a link to the original, so it seems a little redundant.

That said, this will create just a link to the original:

<a href="<?php echo metadata($file, 'uri'); ?>"><?php echo __('Original'); ?></a>

That assumes that in your theme you have a way to get the $file objects for the item.

The site that you link to looks like it is using some javascript to prevent the <a> actually being a link, and instead forcing it to download. Looks like the featherlight library, but not entirely sure.

Thanks Patrick,

I added the code and I get the following error:

InvalidArgumentException
Invalid record passed to recordMetadata.

http://andrespardo.digital/badac/document/16

In my theme I don´t have a way to get the $file objects for item.

I´ve checked several forums but I can´t find a solution.

Thanks for your help.

It does look like you are doing some theme customization. For an item/show page, one way or another you will have access to the $file objects. So, if you could post up your code to GitHub or some other publicly available site, that’ll help us sort out exactly what needs to happen.

Here´s the code
https://github.com/apardor/BADAC

thanks for your help!

It gets a little tricky because of that function that produces all of the markup for all of the files. To produce the link below each image, you have to intrude on the loop.

The easiest way to do that is to create a custom.php file and use the filter available:

<?php

add_filter('file_markup', 'badac_markup_filter');

function badac_markup_filter($html, $args) 
{
    $file = $args['file'];
    $link = metadata($file, 'uri');
    $html .= "<a href='$link'>Original</a>";
    return $html;
}
1 Like

wooooooow

It works perfectly.

Thanks a lot Patrick, I really appreciate your help!!!

I just add the following to enable the image to be downloaded:

a href=’$link’ download=‘BADAC’