• Resolved dragongamer54

    (@dragongamer54)


    Hey

    I’m working on a small code snippet I want to use in my website that retrieves the last 6 added media files and shows them on my site.

    I however can’t find the way how to retrieve the unique url of the thumbnail that FooGallery creates when it dynamically resizes the gallery image dimensions (which also crops them).

    Example: https://www.url.com/wp-content/uploads/cache/2015/06/imagename/-2035997427.jpg
    The last -2035997427.jpg is unique for every image.

    How do I retrieve those url’s ?

    Thanks for the help in advance!
    FooGallery is truly an amazing plugin!

    https://www.ads-software.com/plugins/foogallery/

Viewing 4 replies - 1 through 4 (of 4 total)
  • I don’t know if the answer is here, but there are a couple Actions/Filters related to thumbnails here:

    https://docs.fooplugins.com/foogallery/actions-filters/

    Thread Starter dragongamer54

    (@dragongamer54)

    I tried using this filter in my functions.php file:
    add_filter( 'wp_get_attachment_image_src' , 'foogallery_attachment_html_image', 10 , 2 );

    However I’m fairly new in using filters and this filter doesn’t return any results to my website.

    I get my image url’s through the following code: wp_get_attachment_image_src($attachment->ID, 'full')[0]

    Plugin Author bradvin

    (@bradvin)

    you can see how it is done in the files includes/class-thumbnails.php

    You would have to do something like this:

    $image_url = wp_get_attachment_image_src($attachment->ID, 'full')[0];
    
    $args = array(
       'width'  => 300,
       'height' => 300,
       'crop'   => true
    );
    
    return wpthumb( $image_url , $args );
    Thread Starter dragongamer54

    (@dragongamer54)

    Thanks bradvin, that did the trick!

    This is the source code on how to show the latest 6 media images added to a wordpress website:
    Place this in your custom-theme-template file:

    <?php
                          $args = array(
                              'post_type' => 'attachment',
                              'numberposts' => 6,
                              'post_status' => null
                          );
                          $attachments = get_posts( $args );
                             if ( $attachments ) {
                                 ?>
                                 <div id="foogallery-gallery-000" class="foogallery-container foogallery-default foogallery-link-image foogallery-lightbox-foobox-free spacing-width-25 hover-effect-zoom border-style-square-white alignment-center fbx-instance">
                                 <?php
                                 foreach ( $attachments as $attachment ) {
                                     ?><a href="<?php echo wp_get_attachment_image_src($attachment->ID, 'full')[0]; ?>" data-attachment-id="<?php echo $attachment->ID ?>" class="fbx-link"><img src="<?php echo cropped_image($attachment->ID); ?>" width="210px" height="210px"></a><?php
                                 }
                                 ?>
                                 <div style="clear:both"></div>
                                 </div>
                                <?php
                             }
                        ?>

    Place this in your function.php file:

    function cropped_image($attachment){
            $image_url = wp_get_attachment_image_src($attachment, 'full')[0];
    
            $args = array(
                'width'  => 300,
                'height' => 300,
                'crop'   => true
            );
    
            return wpthumb( $image_url , $args );
        }

    Note that this code only works if you include the foogallery stylesheet in your theme.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Getting the unique cropped image thumnails’ is closed to new replies.