• Resolved vicus

    (@vicus)


    Hello,
    Frist thanks a lot for this very usefull and complete plugin ??

    It must be realy simple but i didn’t find the answer : I was wondering how to do for the link to my file to be in the icon and in the title of my file.

    If didn’t add the icon the link is on the title of the file but with the icon it is only on the icon. I’ld like the both to be clickable.

    here is my code :

    [mla_gallery post_parent=all attachment_category=’presse’ orderby=date order=desc posts_per_archive_page=10 post_mime_type=all mla_caption='{+title+}, {+date+}’ link=file columns=2 mla_itemwidth=40 mla_float=left size=icon ]

    I’ld also like my format date to be only : dmy without the hour, is that possible?

    Thanks for your attention

    https://www.ads-software.com/plugins/media-library-assistant/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author David Lingren

    (@dglingren)

    Thanks for the compliment, for your question and for posting the source text of your [mla_gallery] shortcode.

    Making the {+title+} portion of your caption a clickable link is a bit tricky. The obvious answer might be:

    mla_caption='<a href="{+file_url+}">{+title+}</a>, {+date+}'

    But that fails because you can’t add raw HTML in the parameter value. You could define a custom markup template and add your modified caption there, but you’d still have the second part of your question (reformat the date) to deal with.

    You can solve both of your needs by adding a bit of PHP code to one of the filters provided by [mla_gallery]. In fact, the date reformat question was answered in this earlier support topic:

    format date

    Have a look at that topic, which will tell you find and modify the example code provided with MLA. To accomplish both parts of your requrements, replace the mla_gallery_item_values_filter with this version:

    public static function mla_gallery_item_values_filter( $item_values ) {
        /*
         * For this example, we will reformat the 'date' value as d/m/Y. We use a shortcode parameter of our
         * own to do this on a gallery-by-gallery basis, leaving other [mla_gallery] instances untouched.
         */
        if ( isset( self::$shortcode_attributes['my_filter'] ) && 'format date' == self::$shortcode_attributes['my_filter'] ) {
    
            /*
             * Default format is YYYY-MM-DD HH:MM:SS (HH = 00 - 23), or 'Y-m-d H:i:s'
             * Convert to UNIX timestamp so any reformat is possible
             */
            $old_date = $item_values['date'];
            $timestamp = mktime( substr( $old_date, 11, 2 ), substr( $old_date, 14, 2 ), substr( $old_date, 17, 2 ), substr( $old_date, 5, 2 ), substr( $old_date, 8, 2 ), substr( $old_date, 0, 4 ) );
    
            /*
             * Update the $item_values and pass them back from the filter.
             */
            $item_values['date'] = date( 'd/m/Y', $timestamp );
    
            /*
             * Compose a new caption with a "clickable" document title.
             */
            $item_values['caption'] = sprintf( '<a href="%1$s">%2$s</a><br>%3$s', $item_values['file_url'], $item_values['title'], $item_values['date'] );
    
            return $item_values;
        }
    }

    Once that’s done, replace the mla_caption='{+title+}, {+date+}' parameter in your shortcode with this one: my_filter="format date". That will be picked up by the filter code and your caption should come out the way you want.

    I’m going to mark this topic resolved for now, but feel free to update it if you have any problems or further questions. Thanks for your interest in the plugin.

    Thread Starter vicus

    (@vicus)

    I just want to thank you, your code do exactly the job ! ??
    And thanks again for this usefull plugin!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘link to the pdf on the title and the icon’ is closed to new replies.