WordPress.org

Ready to get started?Download WordPress

Forums

Promotion Slider
Use different images and layouts for different slider (19 posts)

  1. MCWebdesign
    Member
    Posted 2 years ago #

    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/

  2. Micah Wood
    Member
    Plugin Author

    Posted 2 years ago #

    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';
        }
    }
  3. MCWebdesign
    Member
    Posted 2 years ago #

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

  4. MCWebdesign
    Member
    Posted 2 years ago #

    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...

  5. Micah Wood
    Member
    Plugin Author

    Posted 2 years ago #

    @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.

  6. MCWebdesign
    Member
    Posted 2 years ago #

    @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

  7. Micah Wood
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  8. MCWebdesign
    Member
    Posted 2 years ago #

    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

  9. MCWebdesign
    Member
    Posted 2 years ago #

    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' );
  10. Micah Wood
    Member
    Plugin Author

    Posted 2 years ago #

    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 );
      }
    ?>
  11. MCWebdesign
    Member
    Posted 2 years ago #

    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!

  12. Micah Wood
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  13. MCWebdesign
    Member
    Posted 2 years ago #

    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

  14. Micah Wood
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  15. lcsci
    Member
    Posted 1 year ago #

    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?

  16. Micah Wood
    Member
    Plugin Author

    Posted 1 year ago #

    @ 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;
    }
  17. lcsci
    Member
    Posted 1 year ago #

    Woohoo! It works!
    That makes a lot of sense now that I see it. Duh! :)
    Thanks very much! It's a great simple slider you have here.
    ~B.G.

  18. Kim_Diamond
    Member
    Posted 1 year ago #

    Hi Micah,

    I was wondering if you could help me?

    I am using the Flexability 3 theme. I am using the slider in my
    sidebar currently.

    I am trying to get rid of the gray area around my images in my
    slider?

    I tried using this code in my style ccs sheet but no results.
    here is my sites side bar.
    Internet Advertising Deals

    div.promo_slider div.panel.panel-1 {
    	background-image: none;
    }
    
    I also tried this code in widget and css style sheet
    
    div.promo_slider div.panel {background-image: none;}

    I also tried it in the widget and still gray box around my image
    slider...

    Any suggestions on how I might get rid of the

    Gray Box in my sidebar.

    Thank You

    Kim_Diamond

  19. Micah Wood
    Member
    Plugin Author

    Posted 1 year ago #

    @Kim_Diamond

    Try this instead:

    div.promo_slider .panel { background: none; }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic