Home › Forums › Calendar Products › Events Calendar PRO › Struggling to Set Medium Image Size in New Widget
- This topic has 5 replies, 2 voices, and was last updated 8 years, 1 month ago by
Raymond Gillespie.
-
AuthorPosts
-
February 24, 2018 at 12:10 pm #1463010
Raymond Gillespie
ParticipantHello,
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?
February 26, 2018 at 9:11 pm #1464504Cliff
MemberHi, Raymond. I don’t see anywhere in your code mentioning “image” or “featured” — where/how is the featured image thumbnail coming through?
February 27, 2018 at 6:11 am #1464737Raymond Gillespie
ParticipantHi,
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.
February 27, 2018 at 9:09 am #1465044Cliff
MemberThat 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.
March 21, 2018 at 9:35 am #1485033Support Droid
KeymasterHey 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 -
AuthorPosts
- The topic ‘Struggling to Set Medium Image Size in New Widget’ is closed to new replies.
