Support » Plugin: Promotion Slider » [Plugin: Promotion Slider] Use different images and layouts for different slider

  • Resolved MCWebdesign

    (@mcwebdesign)


    Hi I have 2 promotion sliders on my homepage (currently being developed on localhost). The Sliders both work fine (they are in text widgets). One is straightforward and is just using the featured images from the promotions.

    The second slider I want to show a thumbnail of the image on the left with the excerpt to the right of it. I have re worked some css to get the image to display on the left and the excerpt on the right but i want the slider to show a thumbnail of the image rather than the whole image.

    Many Thanks in advance for any assistance.

    http://wordpress.org/extend/plugins/promotion-slider/

Viewing 15 replies - 1 through 15 (of 18 total)
  • Plugin Author Micah Wood

    (@woodent)

    Just ensure that you have set an id in the shortcode, like this:

    [promo_slider id="slider2"]

    Next, use the promoslider_image_size_by_id filter to customize the image size for that specific slider:

    function ( $args ) {
        if( isset( $args['id] && $args['id'] == 'slider2' )  ) {
            $args['image_size'] = 'thumbnail';
        }
    }

    Thanks micah. Where would this code go. Would it need added to the slider code or to functions.php.

    Having tried it in both files I am getting a parse error as follows with the above cods

    Parse error: syntax error, unexpected ‘(‘, expecting T_STRING in C:\xampp\htdocs\wptest\wp-content\plugins\promotion-slider\index.php on line 431

    or

    Parse error: syntax error, unexpected T_BOOLEAN_AND, expecting ‘,’ or ‘)’ in C:\xampp\htdocs\wptest\wp-content\themes\kingschurchkeswick\functions.php on line 170

    apologies if i’m missing something obvious…

    Plugin Author Micah Wood

    (@woodent)

    @mcwebdesign,

    No, sorry… my bad. Here is the updated code:

    function ( $args ) {
        if( isset( $args['id'] ) && $args['id'] == 'slider2'  ) {
            $args['image_size'] = 'thumbnail';
        }
    }

    That would go into your active theme’s functions.php file.

    @micah

    Thanks for this update. I no longer get any errors but the image size doesn’t appear to change. The only other edit i have done is to some CSS:

    .textwidget .promo_slider_wrapper {
    margin: 0 0 0 0;
    }
    
    #testimony .promo_slider_excerpt {
    top: 0;
    left: 30%;
    width: 65%;
    }

    My shortcode is:

    [promoslider id="testimony" width="100%" height="200px" category="testimony" display_title="none" display_nav="none" pause_on_hover="pause" display_excerpt="excerpt"]

    and i changed ‘slider2’ in your code to ‘testimony’

    Matt

    Plugin Author Micah Wood

    (@woodent)

    Sorry again, I probably didn’t make it clear enough that you have to link the function up to the filter like this:

    add_filter( 'promoslider_image_size_by_id', 'change_promoslider_image_size' );
    
    function change_promoslider_image_size( $args ) {
        if( isset( $args['id'] ) && $args['id'] == 'testimony'  ) {
            $args['image_size'] = 'thumbnail';
        }
    }

    Again, my bad. I should have tested the code before posting it.

    Thanks again for looking into this for me however it still isn’t making a difference to my slider. Just wondering whether it might be possible to actually add an image size option for shortcode use (a future feature perhaps?). Though if you have this working, maybe i have a conflict somewhere?

    My apologies i’m just not quite there and still learning php and wordpress interactions etc.

    Matt

    MCWebdesign

    (@mcwebdesign)

    Hi Micah I have just been coming back to this for another project and am still having issues with this here is my current code – neither options are working:

    Am i missing something obvious here? Do i need to add anything to the shortcodes after putting this in functions.php?

    if ( function_exists( 'add_theme_support' ) ) {
    	add_theme_support( 'post-thumbnails' );
    	set_post_thumbnail_size( 150, 150 );
    	add_image_size('slider', 1140, 400, true );
    	add_image_size('custom_post_thumb_large', 708, 400, true );
    	add_image_size('custom_post_thumb_small', 100, 100, true );
    }
    function events_promoslider_image_size( $args ) {
        if( isset( $args['id'] ) && $args['id'] == 'events-home'  ) {
            $args['image_size'] = 'custom_post_thumb_large'; } }
    add_filter( 'promoslider_image_size_by_id', 'events_promoslider_image_size' );

    Plugin Author Micah Wood

    (@woodent)

    You should actually be using the ‘after_theme_setup’ action hook to add your custom image sizes:

    <?php
      add_action( 'after_setup_theme', 'custom_image_sizes' );
      function custom_image_sizes() {
        add_theme_support( 'post-thumbnails' );
        set_post_thumbnail_size( 150, 150 );
        add_image_size('slider', 1140, 400, true );
        add_image_size('custom_post_thumb_large', 708, 400, true );
        add_image_size('custom_post_thumb_small', 100, 100, true );
      }
    ?>
    MCWebdesign

    (@mcwebdesign)

    Ok so I’ve changed the way it adds the images but the image slider is still showing the full sized image, not a cropped image as I’m telling it too. The only change I’ve made is added the above code into functions.php then edited as per your suggestion. When I go into the images folder on the server all the different sizes are there and I can use the custom sizes everywhere else in my theme, but not in the slider!

    Plugin Author Micah Wood

    (@woodent)

    Ah, just a side note, when you have existing images and create a new image size, you have to regenerate your image sizes using a plugin like Regenerate Thumbnails.

    The events_promoslider_image_size() function from your previous code will automatically use your custom image size, if it exists. There will not be any settings anywhere in the admin where you will choose a size.

    Hi Micah,

    Thanks for that, but I picked that up quite early on. At the moment I’m working on a clean install with new images each time i make a code change (working locally with only a handful of images). The image sizes are being generated ok, it’s just the slider isn’t picking them up.

    Matt

    Plugin Author Micah Wood

    (@woodent)

    Unless you did some customization of the slider output, the default functions in combination with the filter should pull the correct one. The only things I can think of are to make sure the filter is being applied properly and that whichever display function is being used is properly calling it.

    Hi Micah,

    I pasted the following into my theme’s functions.php:

    add_filter( 'promoslider_image_size_by_id', 'change_promoslider_image_size' );
    
    function change_promoslider_image_size( $args ) {
        if( isset( $args['id'] ) && $args['id'] == 'new_slider'  ) {
            $args['image_size'] = 'thumbnail';
        }
    }

    I’d like my slider with id=”new_slider” to show the thumbnail versions of the post images. It still shows the full images, which is the default setting, as I also have a large slider on the home page. Did I paste the code into the right place? Or does the filter go elsewhere?

    Plugin Author Micah Wood

    (@woodent)

    @ lcsci,

    You are 95% correct in your code, however ‘promoslider_image_size_by_id’ is a filter, not an action. This means that if you don’t return a value in your function, then nothing will happen.

    Try this instead:

    add_filter( 'promoslider_image_size_by_id', 'change_promoslider_image_size' );
    
    function change_promoslider_image_size( $args ) {
        if( isset( $args['id'] ) && $args['id'] == 'new_slider'  ) {
            $args['image_size'] = 'thumbnail';
        }
        return $args;
    }
Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘[Plugin: Promotion Slider] Use different images and layouts for different slider’ is closed to new replies.