Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swapped out series post widget image location for image size + alignment options #1734

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions inc/widgets/largo-series-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function widget( $args, $instance ) {
$instance['title_link'] = get_term_link( (int) $instance['series'], 'series' );
$term = get_term( $instance['series'], 'series' );
$title = apply_filters( 'widget_title', $term->name, $instance, $this->id_base );
$thumb = isset( $instance['thumbnail_display'] ) ? $instance['thumbnail_display'] : 'small';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was it intended to change the default from medium -> small? Also, is it possible that thumbnail_display could have an unexpected size value and does this need to be handled?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was to copy the functionality from one of our other widgets, so the small default is ok.

It will be a selected from a dropdown, so I doubt there would be an unexpected size value. @benlk Do you know if that's ever happened with the Largo Recent Posts widget that this was copied from?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if it has ever happened.

The template that this widget renders only has cases for small, medium, and large, so an invalid choice or the none option would result in no thumbnail displaying:

https://github.com/INN/largo/blob/67b4dedb252220515243756e96ed2033dd7f0d38/partials/widget-content.php#L9-L30


echo $args['before_widget'];

Expand All @@ -38,7 +39,7 @@ function widget( $args, $instance ) {

$context = array(
'instance' => $instance,
'thumb' => 'medium',
'thumb' => $thumb,
'excerpt' => 'custom_excerpt'
);
largo_render_template('partials/widget', 'content', $context);
Expand Down Expand Up @@ -77,7 +78,8 @@ function update( $new_instance, $old_instance ) {
$instance['num'] = (int)$new_instance['num'];
$instance['series'] = sanitize_key( $new_instance['series'] );
$instance['show_byline'] = (int) $new_instance['show_byline'];
$instance['thumbnail_location'] = sanitize_key( $new_instance['thumbnail_location'] );
$instance['thumbnail_display'] = sanitize_key( $new_instance['thumbnail_display'] );
$instance['image_align'] = sanitize_key( $new_instance['image_align'] );
return $instance;
}

Expand All @@ -88,7 +90,8 @@ function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array(
'num' => 4,
'heading' => 'Explore:',
'thumbnail_location' => 'before',
'thumbnail_display' => 'small',
'image_align' => 'left',
'show_byline' => 0,
'series' => 'null')
);
Expand Down Expand Up @@ -123,13 +126,21 @@ function form( $instance ) {
</p>
benlk marked this conversation as resolved.
Show resolved Hide resolved

<p>
<label for="<?php echo $this->get_field_id('thumbnail_location'); ?>"><?php _e('Thumbnail position on first post', 'largo'); ?>:</label>
<select name="<?php echo $this->get_field_name('thumbnail_location'); ?>" id="<?php echo $this->get_field_id('thumbnail_location'); ?>">
<?php
$choices = array( 'before' => __( 'Before Headline', 'largo' ), 'after' => __( 'After Headline', 'largo' ) );
foreach( $choices as $i => $display ) {
echo '<option value="', $i, '"', selected($instance['thumbnail_location'], $i, false), '>', $display, '</option>';
} ?>
<label for="<?php echo $this->get_field_id( 'thumbnail_display' ); ?>"><?php _e( 'Thumbnail Image', 'largo' ); ?></label>
<select id="<?php echo $this->get_field_id( 'thumbnail_display' ); ?>" name="<?php echo $this->get_field_name( 'thumbnail_display' ); ?>" class="widefat" style="width:90%;">
<option <?php selected( $instance['thumbnail_display'], 'small'); ?> value="small"><?php _e( 'Small (60x60)', 'largo' ); ?></option>
<option <?php selected( $instance['thumbnail_display'], 'medium'); ?> value="medium"><?php _e( 'Medium (140x140)', 'largo' ); ?></option>
<option <?php selected( $instance['thumbnail_display'], 'large'); ?> value="large"><?php _e( 'Large (Full width of the widget)', 'largo' ); ?></option>
<option <?php selected( $instance['thumbnail_display'], 'none'); ?> value="none"><?php _e( 'None', 'largo' ); ?></option>
</select>
</p>

<!-- Image alignment -->
<p>
<label for="<?php echo $this->get_field_id( 'image_align' ); ?>"><?php _e( 'Image Alignment', 'largo' ); ?></label>
<select id="<?php echo $this->get_field_id( 'image_align' ); ?>" name="<?php echo $this->get_field_name( 'image_align' ); ?>" class="widefat" style="width:90%;">
<option <?php selected( $instance['image_align'], 'left'); ?> value="left"><?php _e( 'Left align', 'largo' ); ?></option>
<option <?php selected( $instance['image_align'], 'right'); ?> value="right"><?php _e( 'Right align', 'largo' ); ?></option>
</select>
</p>

Expand Down