Struggling to Set Medium Image Size in New Widget

Home Forums Calendar Products Events Calendar PRO Struggling to Set Medium Image Size in New Widget

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1463010
    Raymond Gillespie
    Participant

    Hello,

    I created a topic about this a few weeks ago and I thought I had it sorted but it does look like I do. I am currently using the following code to create a custom widget that displays recently added events:

    `class EventsListWidget_NewlyAddedEvents {
    protected $constraints = array(
    ‘sidebar_id’ => null,
    ‘widget_id’ => null,
    ‘widget_title’ => null
    );

    public function __construct( array $constraints = array() ) {
        $this->constraints = array_merge( $this->constraints, $constraints );
        add_filter( 'widget_display_callback', array( $this, 'setup' ), 10, 3 );
    }
    
    public function setup( $instance, $widget, $args ) {
        // We're interested only in the (advanced or regular) events list widgets
        $targets = array( 'tribe-events-adv-list-widget', 'tribe-events-list-widget' );
        if ( ! in_array( $widget->id_base, $targets ) ) return $instance;
    
        // Check for constraints
        if ( ! $this->constraints_met( $instance, $args ) ) return $instance;
    
        // Modify behaviour
        add_filter( 'tribe_events_list_widget_query_args', array( $this, 'order_by_latest' ) );
        return $instance;
    }
    
    protected function constraints_met( $instance, $args ) {
        $fail = false;
    
        // Should only run within a specific sidebar?
        if ( ! is_null( $this->constraints['sidebar_id'] ) && $this->constraints['sidebar_id'] !== $args['id'] )
            $fail = true;
    
        // Should only run in relation to a specific instance of the widget?
        if ( ! is_null( $this->constraints['widget_id'] ) && $this->constraints['widget_id'] !== $args['widget_id'] )
            $fail = true;
    
        // Should only run when the widget title is set to something specific?
        if ( ! is_null( $this->constraints['widget_title'] ) && $this->constraints['widget_title'] !== $instance['title'] )
            $fail = true;
    
        return ! $fail;
    }
    
    public function order_by_latest( $args ) {
        // Don't interfere in other queries
        remove_filter( 'tribe_events_list_widget_query_args', array( $this, 'order_by_latest' ) );
    
        // Tweak the actual orderby clause
        add_filter( 'posts_orderby', array( $this, 'override_orderby' ), 100 );
        return $args;
    }
    
    public function override_orderby( $orderby_sql ) {
        global $wpdb;
    
        // Don't interfere in other queries
        remove_filter( 'posts_orderby', array( $this, 'override_orderby' ), 100 );
    
        return "$wpdb->posts.post_date DESC, $orderby_sql";
    }
    

    }

    /**
    * By itself, the following line will impact all list widgets. However it may
    * be desirable to impact just one. To achieve this, it is possible to specify
    * one or more constraints.
    *
    * Valid constraints include:
    *
    * sidebar_id (the ID of the sidebar – list widgets in other sidebars will not be affected)
    * widget_id (the specific widget ID itself)
    * widget_title (if you don’t know how to determine the widget/sidebar ID, you can specify the title)
    *
    * Example:
    *
    * new EventsListWidget_NewlyAddedEvents( array(
    * ‘sidebar_id’ => ‘sidebar-1’
    * ) );
    *
    * Or:
    *
    * new EventsListWidget_NewlyAddedEvents( array(
    * ‘widget_title’ => ‘Newly Added Events!’
    * ) );
    */
    new EventsListWidget_NewlyAddedEvents( array(
    ‘widget_title’ => ‘Recently Added Events’
    ) );`

    It all works fine apart from the images, which are using the 150×150 thumbnails instead of the medium image size like other widgets. Can you help?

    #1464504
    Cliff
    Member

    Hi, Raymond. I don’t see anywhere in your code mentioning “image” or “featured” — where/how is the featured image thumbnail coming through?

    #1464737
    Raymond Gillespie
    Participant

    Hi,

    Thanks for the update. I tried adding the following code to set the image size:

    add_filter( 'tribe_events_list_widget_thumbnail_size', 'custom_list_widget_thumbnail_size' );
    function custom_list_widget_thumbnail_size() {
    return 'full';
    }

    However, that didn’t seem to work. What I don’t understand is how the widget image size is set – the default widgets appear to have them set as medium or full, it’s only the custom widget (“Recently Added Events”) that shows the 150×150 thumbnail size.

    #1465044
    Cliff
    Member

    That should work. I’d recommend switching to a WordPress default theme like Twenty Fifteen, Twenty Sixteen, Twenty Seventeen, etc. and see if it still doesn’t take effect.

    Either way, you might want to add a higher priority, like this:

    add_filter( 'tribe_events_list_widget_thumbnail_size', 'custom_list_widget_thumbnail_size', 50 );

    Please let me know how this goes for you.

    #1485033
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Struggling to Set Medium Image Size in New Widget’ is closed to new replies.