WordPress.org

Ready to get started?Download WordPress

Forums

Gallery to Slideshow
[resolved] How to hook a gallery shortcode attributes to FlexSlider params (8 posts)

  1. alvelig
    Member
    Posted 1 year ago #

    Hi all!

    My idea is to improve the plugin to have several attributes in the shortcode, that I could pass to the FlexSlider js param array.

    I'm trying to pass [gallery slideshow="auto"].

    Here's the code:

    //member of class MV_Gallery_To_Slideshow
    function set_slideshow( $params, $attr ){
    		switch($attr["slideshow"]) {
    		    case "auto":
    			$params['slideshow'] = true;
    		    break;
    		    default:
    			$params['slideshow'] = false;
    		}
    		return $params;
    	}
    ....
    
     function enqueue_script() {
    ...
    
    add_filter( 'mv_gallery_to_slideshow_attr', 'set_slideshow', 10, 2 );
    
                wp_localize_script( 'gallery-to-slideshow', 'mv_gallery_to_slideshow_js_params', apply_filters( 'mv_gallery_to_slideshow_js_params', $params ) );
    }

    What am I doing wrong, please?

    http://wordpress.org/extend/plugins/gallery-to-slideshow/

  2. alvelig
    Member
    Posted 1 year ago #

    Had to take my head to the code and finally found a solution:

    I moved

    // FlexSlider Params
                $params = array( ... );
    wp_localize_script( 'gallery-to-slideshow', 'mv_gallery_to_slideshow_js_params', apply_filters( 'mv_gallery_to_slideshow_js_params', $params ) );

    from function enqueue_script() { ... }

    to

    function gallery( $gallery_html, $attr ) {
    ...
    
    // FlexSlider Params
                $params = array( ... );
    
    if( isset( $attr['slideshow'] ) ){
    		$params['slideshow'] = $attr['slideshow'];
    	    }
    
    	    wp_localize_script( 'gallery-to-slideshow', 'mv_gallery_to_slideshow_js_params', apply_filters( 'mv_gallery_to_slideshow_js_params', $params ) );
    ...
    }
  3. parkersweb
    Member
    Posted 1 year ago #

    Hey Alvelig,

    This sounds perfect for what I'm trying to achieve - but I'm struggling to follow what you're doing. Did you do this by adding a filter in your function.php file which adds the shortcode attributes, and passes them into a localized script, or did you modify the core plugin file?

    If there's any chance you could post a more complete example that would be very much appreciated!

    Thanks

    Andrew

  4. alvelig
    Member
    Posted 1 year ago #

    Hi Andrew!

    Actually, i was editing the plugin files (inc/gallery-to-slideshow-class.php)... And the second post is more a feature request for the developers, than an out-of-the-box solution.

    But as far as functions.php is concerned, I can assume that adding these lines to functions.php should do the job. Actually, i tested it, heh )

    add_filter( 'post_gallery', 'my_hook_for_gallery', 11, 2 );
    
    function my_hook_for_gallery ( $gallery_html, $attr ) {
    	if( isset( $attr['slideshow'] ) ){
    		$params['slideshow'] = $attr['slideshow'];
    
    	    wp_localize_script( 'gallery-to-slideshow', 'mv_gallery_to_slideshow_js_params', apply_filters( 'mv_gallery_to_slideshow_js_params', $params ) );
    }
    }

    Update: the $attr['slideshow'] can be any attribute of the gallery shortcode.

  5. parkersweb
    Member
    Posted 1 year ago #

    Hey Alvelig,

    Thanks so much - really much appreciated.

    After some fiddling last night I managed to get it working - but for some reason it only works if I add

    return $gallery_html;

    within the function - otherwise it outputs the standard gallery html. Does that sound right to you?

    Andrew

  6. alvelig
    Member
    Posted 1 year ago #

    Andrew,

    that sounds right and so is it, but now I wonder, why the code above worked in my case without return $gallery_html; :)

    Another thing: did you manage to do anything with MCE Rich Text Editor. I am looking for a solution to add gallery and its attributes not in HTML mode, but in Visual.

  7. parkersweb
    Member
    Posted 1 year ago #

    Hi Alvelig,

    I can't find a way of doing that immediately - but this plugin seems to be doing something along those lines:

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

    I'm also looking for way to link each slide to a url - one that isn't the full-size image or the attachment url (ideally the link-url on the image). You don't know if that's possible do you?

    Andrew

  8. alvelig
    Member
    Posted 1 year ago #

    Andrew,

    thank you, your link is really helpful, that plugin seems to be awesome. :) But a bit sophisticated, so for the current project I won't switch to it.

    As for external link on slides, it's possible using add_post_meta()/ get_post_meta(). I think you can use an a little outdated though useful plugin: http://wordpress.org/extend/plugins/media-custom-fields/ which adds custom fields to post attachments (media posts).
    and then you'll have to get your custom meta field with get_post_data()

    Sorry for not giving you a complete solution, but this should help resolve your problem.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.