WordPress.org

Ready to get started?Download WordPress

Forums

NextGEN Gallery
[resolved] Adding a download link/button (15 posts)

  1. nbruley
    Member
    Posted 3 years ago #

    I have figured out how to add an automatic download link on an imagebrowser page by linking to force-download.php but I am not sure how to reference the file location in the gallery view since the image links to the imagebrowser page, not to the image itself.

    Is there a variable that works in the gallery page when using imagebrowser that would give me the path to each image? Thanks!

    See example here:
    Does not work (Bajar means download): http://tesorodigital.mysitecreations.com/contenido/galeria/508-cartas-graficas/
    Works: http://tesorodigital.mysitecreations.com/contenido/galeria/508-cartas-graficas/?pid=1

    http://wordpress.org/extend/plugins/nextgen-gallery/

  2. nbruley
    Member
    Posted 3 years ago #

    I tried $image->href and this almost works, but it adds in the whole thumbnail and everything, and I just want a link to the picture.

    In another post I see referenced a method to access the database

    <?php $album = nggdb::find_album( get_query_var('album') ); ?>

    Does anyone know the function like this to get the proper data for the current image href?

    Thank you.

  3. trewknowledge
    Member
    Posted 3 years ago #

    I am also looking to have the ability to have a download button on the Gallery page.

    I have tried a couple of things but have had no luck.

  4. nbruley
    Member
    Posted 3 years ago #

    If I don't use imagebrowser I think I got it to work on the gallery page, but with imagebrowser I can't get it yet. Oh well, at least I have it on imagebrowser for now.

  5. trewknowledge
    Member
    Posted 3 years ago #

    Can you please explain how you got it to work without using imagebrowser.

    Is it something that comes with NextGen gallery? or is this something that you created?

  6. nbruley
    Member
    Posted 3 years ago #

    It involves adding some code to /wp-content/plugins/nextgen-gallery/view/gallery-caption.php (or you probably want to make your own custom theme by copying the .php file and naming it gallery-mytemplate.php and referencing [template=mytemplate]

    Here's a snippet from my gallery-template file that includes modified code:
    [Code moderated as per the Forum Rules. Please use the pastebin]

    Then you need to upload force-download.php to your home directory.
    Code for this file is as follows:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    You'll probably have to tweak the code to your liking. Instead of the hyperlink you can make it a button.

    I think this would work. You may have to adjust other settings in the gallery. I think you have to use the caption template, can't remember for sure. See if it works and let me know.

  7. nbruley
    Member
    Posted 3 years ago #

    Sorry, I edited the code above slightly. The important line is

    <!-- ADD DOWNLOAD LINK, changed image-caption to image-alttext NB ???  -->
    <span><?php echo $image->alttext ?><br /><?php echo $image->caption; ?><br /><a href=" <?php home_url(); ?> /force-download.php?file=<?php echo substr(parse_url($image->imageURL,PHP_URL_PATH),2); ?> ">Download</a></span>

    I tested without imagebrowser and it works on my settings.

  8. nbruley
    Member
    Posted 3 years ago #

    Another note: the "2" in the following code may need to be "1" depending on how the location of the gallery images is entered in the gallery configuration page. If it begins with a "/" you'll need a 2 to eliminate it, if it begins with a folder name, you need a 1.
    substr(parse_url($image->imageURL,PHP_URL_PATH),2);

  9. nbruley
    Member
    Posted 3 years ago #

    UPDATE: I decided to forget about imagebrowser and just use the shutter style, so the links in the first post no longer demonstrate the problem.

  10. davejworth
    Member
    Posted 2 years ago #

    Hi nbruley - I've been searching and searching for a solution like the one you are describing. Could you re-post the PHP that has been moderated out?

    Many thanks!

  11. nbruley
    Member
    Posted 2 years ago #

    Force download code (images/audio):
    http://pastebin.com/c7RxpsPP

    my NextGEN template file (complete)
    http://pastebin.com/Z709fu0f

    Hope that helps.

  12. The Gal
    Member
    Posted 2 years ago #

    Sir, you are a genius. I just used your code as well and it worked so well, I quite literally exclaimed aloud with joy. :D THANK YOU for sharing your work!!!

  13. davejworth
    Member
    Posted 2 years ago #

    nbruley - fantastic! Worked like a dream.

    Many thanks.

  14. ernaparalla
    Member
    Posted 2 years ago #

    This looks like what I'm trying to do butI'm not using either of these galleries. I have a single image in each of my WP posts and want to add a link within the post (located in on single.php file) to download that image (ideally, I'll configure it to display 3 links to allow users to download a large, medium, or small image).

    Is this possible with what you have here?
    Thanks!

  15. nbruley
    Member
    Posted 2 years ago #

    ernaparalla, yes, this should work. If I understand you correctly, you would use only the force-download.php file and create a link to download a specific file using a URL like
    mySite.com/force-download.php?file=small/myFile.jpg
    mySite.com/force-download.php?file=medium/myFile.jpg
    mySite.com/force-download.php?file=large/myFile.jpg

    In your case, you may wish to put the different sized images in different folders and call them by the same file name. This might simplify the php coding.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.