HG Slider
[resolved] Added Shortcodes! (4 posts)

  1. gpspake
    Posted 2 years ago #

    I typically don't like to bother with templates if I don't absolutely have to so I whipped up some short code support for this thing. Thanks, as usual to Smashing as their guides are awesome. This shortcode puts the slider in a div and allows you to pass 2 arguments: the div class and the slider id. And now it's working great!

    I added all this to functions.php With Hal's instructions but you could probably wrap this up in the plugin just as easily.

    so here goes...

    First of all this is all Hal's stuff, tweaked for my site of course.

    function set_flexslider_hg_rotators()
      $rotators = array();
      $rotators['paintings'] = array( 'size' => 'paintings-rotator' );
      $rotators['drawings'] = array( 'size' => 'drawings-rotator' );
      $rotators['photography'] = array( 'size' => 'photography-rotator' );
      $rotators['sculpture'] = array( 'size' => 'sculpture-rotator' );
      return $rotators;
    add_filter('flexslider_hg_rotators', 'set_flexslider_hg_rotators');
    add_image_size( 'paintings-rotator', '550', '250', true );

    Then we bring in the shortcode magic (Thanks again for this smashing guide which has been helpful more than once.)

    add_shortcode('gsflexslide', 'gsflexslide_function');
    function gsflexslide_function($atts){
          'slider_id' => 'paintings',
          'class' => 'gsflexslide',
       ), $atts));
       $return_string = '<div class="'.$class.'">';
       if(function_exists('show_flexslider_rotator'))  { show_flexslider_rotator( $slider_id );};
       $return_string .= '</div>';
       return $return_string;

    And the shortcode:
    [gsflexslide] defaults to 'paintings with a class of .gsflexslide
    [gsflexslide class="whatever" slider_id="whatever"] selects the whatever slider and puts it in a div with the class .whatever.

    And that's it.

    I hope this helps someone. I'm brand new to php so if I made any mistakes feel free to let me know.

    Now that I have it on my pages, I need to figure out how to make it slide instead of fade. I'll share when I do.


  2. kwatts22
    Posted 2 years ago #

    This is a good way and one of the most simple ways to added it. Otherwise you would have to edit the index.php page and add it into your template.

  3. Hal Gatewood
    Plugin Author

    Posted 2 years ago #

    I'll add a custom widget and shortcode to the plugin by default in the coming weeks. Thanks for this.

  4. Hal Gatewood
    Plugin Author

    Posted 2 years ago #

    A shortcode has been added to the latest version of the plugin.

    [flexslider slug=homepage]

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • HG Slider
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic