Skip to content

Commit 758a5b8

Browse files
authored
Merge pull request #4406 from Codeinwp/feat/single-post-thumbnail-settings
[Feat] Adds image size options to single post thumbnail
2 parents 5d20c31 + 53470da commit 758a5b8

File tree

3 files changed

+104
-6
lines changed

3 files changed

+104
-6
lines changed

inc/core/styles/frontend.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,19 @@ private function setup_single_post_style() {
818818
'selectors' => '.nv-single-post-wrap',
819819
'rules' => $spacing_rules,
820820
];
821+
822+
$this->_subscribers['.nv-thumb-wrap img'] = [
823+
'aspect-ratio' => [
824+
'key' => 'neve_post_thumbnail_aspect_ratio',
825+
'default' => 'original',
826+
'filter' => function ( $css_prop, $value, $meta, $device ) {
827+
if ( $value === 'original' ) {
828+
return '';
829+
}
830+
return sprintf( '%s: %s; object-fit: cover;', $css_prop, str_replace( '-', '/', $value ) );
831+
},
832+
],
833+
];
821834
}
822835

823836
/**

inc/customizer/options/layout_single_post.php

Lines changed: 90 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,17 @@ private function header_layout() {
293293
* Add content order control.
294294
*/
295295
private function control_content_order() {
296+
$ar_choices = [
297+
'original' => esc_html__( 'Original', 'neve' ),
298+
'1-1' => '1:1',
299+
'4-3' => '4:3',
300+
'16-9' => '16:9',
301+
'2-1' => '2:1',
302+
'4-5' => '4:5',
303+
'3-4' => '3:4',
304+
'2-3' => '2:3',
305+
];
306+
296307
$all_components = [
297308
'title-meta' => [
298309
'label' => __( 'Title & Meta', 'neve' ),
@@ -334,22 +345,32 @@ private function control_content_order() {
334345
'thumbnail' => [
335346
'label' => __( 'Thumbnail', 'neve' ),
336347
'controls' => [
337-
'neve_post_cover_height' => [
348+
'neve_post_thumbnail_size' => [
349+
'label' => esc_html__( 'Image Size', 'neve' ),
350+
'type' => 'select',
351+
'choices' => $this->get_image_size_as_choices(),
352+
],
353+
'neve_post_thumbnail_aspect_ratio' => [
354+
'label' => esc_html__( 'Image Aspect Ratio', 'neve' ),
355+
'type' => 'select',
356+
'choices' => $ar_choices,
357+
],
358+
'neve_post_cover_height' => [
338359
'type' => 'responsive-range',
339360
],
340-
'neve_post_cover_padding' => [
361+
'neve_post_cover_padding' => [
341362
'type' => 'responsive-spacing',
342363
],
343-
'neve_post_cover_hide_thumbnail' => [
364+
'neve_post_cover_hide_thumbnail' => [
344365
'label' => __( 'Hide featured image', 'neve' ),
345366
'type' => 'toggle',
346367
],
347-
'neve_post_cover_blend_mode' => [
368+
'neve_post_cover_blend_mode' => [
348369
'label' => __( 'Blend mode', 'neve' ),
349370
'type' => 'select',
350371
'choices' => $this->get_blend_mode_choices(),
351372
],
352-
'neve_post_cover_overlay_opacity' => [
373+
'neve_post_cover_overlay_opacity' => [
353374
'label' => __( 'Overlay opacity', 'neve' ),
354375
'type' => 'range',
355376
],
@@ -384,6 +405,44 @@ private function control_content_order() {
384405
*/
385406
$components = apply_filters( 'neve_single_post_elements', $all_components );
386407

408+
$this->add_control(
409+
new Control(
410+
'neve_post_thumbnail_size',
411+
[
412+
'default' => 'neve-blog',
413+
'sanitize_callback' => function( $value ) {
414+
return array_key_exists( $value, $this->get_image_size_as_choices() ) ? $value : 'neve-blog';
415+
},
416+
],
417+
[
418+
'section' => $this->section,
419+
'type' => 'hidden',
420+
'active_callback' => function() {
421+
return ! $this->is_cover_layout();
422+
},
423+
]
424+
)
425+
);
426+
427+
$this->add_control(
428+
new Control(
429+
'neve_post_thumbnail_aspect_ratio',
430+
[
431+
'default' => 'original',
432+
'sanitize_callback' => function( $value ) use ( $ar_choices ) {
433+
return array_key_exists( $value, $ar_choices ) ? $value : 'original';
434+
},
435+
],
436+
[
437+
'section' => $this->section,
438+
'type' => 'hidden',
439+
'active_callback' => function() {
440+
return ! $this->is_cover_layout();
441+
},
442+
]
443+
)
444+
);
445+
387446
$this->add_control(
388447
new Control(
389448
'neve_layout_single_post_elements_order',
@@ -878,4 +937,30 @@ public function is_boxed_title() {
878937
}
879938
return get_theme_mod( 'neve_post_cover_title_boxed_layout', false );
880939
}
940+
941+
/**
942+
* Get the image size as choices.
943+
*
944+
* @return array
945+
*/
946+
private function get_image_size_as_choices() {
947+
948+
$image_size_values = get_intermediate_image_sizes(); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.get_intermediate_image_sizes_get_intermediate_image_sizes
949+
950+
// Needed in VIP environment to at least provide the blog image size.
951+
if ( ! in_array( 'neve-blog', $image_size_values, true ) ) {
952+
array_push( $image_size_values, 'neve-blog' );
953+
}
954+
955+
array_push( $image_size_values, 'full' );
956+
957+
$image_size_choices = array_map(
958+
function( $value ) {
959+
return ucwords( str_replace( [ '-', '_' ], ' ', $value ) );
960+
},
961+
array_combine( $image_size_values, $image_size_values )
962+
);
963+
964+
return $image_size_choices;
965+
}
881966
}

inc/views/post_layout.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function render_post( $context ) {
104104
echo '<div class="nv-thumb-wrap">';
105105
echo get_the_post_thumbnail(
106106
null,
107-
'neve-blog',
107+
get_theme_mod( 'neve_post_thumbnail_size', 'neve-blog' ),
108108
array( 'class' => $skip_lazy_class )
109109
);
110110
echo '</div>';

0 commit comments

Comments
 (0)