• Resolved carryoncoding

    (@carryoncoding)


    Hi,

    My client has requested modifications to the fancy2 format. The Download button is not required (I could do this with CSS but read on!) and the thumbnail is to provide the link to download.

    I note your comments but I can’t see how to apply these requirements as a filter in this case.

    1. Please could you or the readership suggest how to achieve this as a filter?

    I have built a solution that instead requires modifying includes/templates/fancy2/sdm-fancy-2.php. On line 150, change:

    $output .= '<div class="sdm_fancy2_download_thumbnail">' . $isset_download_thumbnail . '</div>';

    Into:

    $output .= '<div class="sdm_fancy2_download_thumbnail">' . '<a href="' . $download_url . ' target="' . $window_target . '">' . $isset_download_thumbnail . '</a></div>';

    This does the trick but will of course be overwritten next time the plugin is updated.

    2. How do I place this code somewhere where it won’t get overwritten?

    Very many thanks,
    Phil.

    • This topic was modified 6 years, 4 months ago by carryoncoding.
Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Contributor mbrsolution

    (@mbrsolution)

    Hi, I am wondering if you can add this to a child theme? Can you give this a try and report back with the outcome.

    Thank you

    Thread Starter carryoncoding

    (@carryoncoding)

    Happy to give it a try.
    I’m comfortable adding theme files to a child-theme but how would this work with a plugin file?

    Plugin Contributor mbrsolution

    (@mbrsolution)

    Hi, that is a good question. Check the following documentation. Let me know if it helps you or not.

    Regards

    Thread Starter carryoncoding

    (@carryoncoding)

    Haha! Now we’re going full-circle. Thank you for pointing me to your comments about php tweaks but you’ll note I already referred to them above.

    I note your comments but I can’t see how to apply these requirements as a filter in this case.

    Kind regards,
    Phil.

    Plugin Contributor mbrsolution

    (@mbrsolution)

    Hi, my apologies.

    I have submitted a message to the developers to investigate further your request.

    Thank you

    Thread Starter carryoncoding

    (@carryoncoding)

    No worries. Thanks very much – looking forward to resolving.
    All the best,
    Phil.

    Plugin Author mra13

    (@mra13)

    This is not going to be a very trivial change. It does require a bit of advanced coding knowledge.

    The following filter basically lets you FULLY override whatever output the shortcode is going to output:

    
    sdm_download_shortcode_output
    

    So you have to use that filter to fully customize the output of that template. Write the full code for how you want the output to look like (you can copy most of the code from template 1 then modify what you want to). At this stage you can’t just add a couple of lines to make the changes you are after.

    I am going to add a new filter that is just for the thumbnail. That will help you do the customization with less code. I will add the filter hooks in the next release.

    Thread Starter carryoncoding

    (@carryoncoding)

    That’s awesome. Thanks so much for filling this gap. I think we’ll find a lot of use for the new filter. I look forward to the next release.
    Kind regards,
    Phil.

    Thread Starter carryoncoding

    (@carryoncoding)

    Just following up your direction to “Write the full code for how you want the output to look “. I have achieved the required display by modifying the output as follows:

    In file includes/templates/fancy2/sdm-fancy-2.php. from line 144 onwards:

    $output = '';
        $output .= '<div class="sdm_fancy2_item ' . $css_class . '">';
        $output .= '<div class="sdm_fancy2_wrapper">';
    
        $output .= '<div class="sdm_fancy2_download_item_top">';
        
        // Next line modified to put url around image.
        //$output .= '<div class="sdm_fancy2_download_thumbnail">' . $isset_download_thumbnail . '</div>';
        $output .= '<div class="sdm_fancy2_download_thumbnail">' . '<a href="' . $download_url . ' target="' . $window_target . '">' . $isset_download_thumbnail . '</a></div>';
        $output .= '</div>'; //End of .sdm_download_item_top
    
        $output .= '<div class="sdm_fancy2_download_title">' . $item_title . '</div>';

    So should this code now be moved into the filter in functions.php or does more code have to be copied across?

    Plugin Contributor mbrsolution

    (@mbrsolution)

    Hi @carryoncoding, the latest version has two new filters included in the code. Let us know if this works for you.

    kind regards

    Thread Starter carryoncoding

    (@carryoncoding)

    Thanks for taking this forward – I’m sure it will make SDM even more useful than it already is!

    Have you documented the new filters at all or can you point me to where I can see how to use them?
    Thanks,
    Phil.

    Plugin Contributor mbrsolution

    (@mbrsolution)

    Hi, you can use the above documentation link I shared to learn more about filters. The following are the two new filters added.

    sdm_download_fancy_1_thumbnail
    sdm_download_fancy_2_thumbnail

    Kind regards

    Plugin Author mra13

    (@mra13)

    I have added a code example for it in the following page:
    https://simple-download-monitor.com/simple-download-monitor-filter-hook-reference/

    Thread Starter carryoncoding

    (@carryoncoding)

    Very many thanks for all your help. I was able to take the work you shared and create the required appearance and function.

    Here is the final version based upon your example and using knowledge gained from sdm-fancy-2.php

    // SDM filter to make thumbnail clickable 
    add_filter('sdm_download_fancy_2_thumbnail', 'custom_fancy2_thumb_output', 10, 2);
    function custom_fancy2_thumb_output($thumb_output, $args){
        $download_id = $args['id'];
        $download_thumb_url = get_post_meta($download_id, 'sdm_upload_thumbnail', true);
        $thumb_output = '<a href="' . $homepage . '/?smd_process_download=1&download_id=' . $download_id . '" target="_blank">' . '<img src="' . $download_thumb_url . '" class="sdm_fancy2_thumb_image" />' . '</a>';
        return $thumb_output;
    }

    Please note that I had to correct “get_post_meta($id as that needed to be $download_id. I also needed to change class=”sdm_download_thumbnail_image” into class=”sdm_fancy2_thumb_image”.

    I noticed that $window_target wasn’t visible from within the filter code so had to hardwire the target=”_blank”. I’m sure this could be improved but it seems to work fine!

    Thanks again.
    Phil.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Use thumbnail as link’ is closed to new replies.