• Resolved Giuseppe

    (@mociofiletto)


    Hi David, I have seen your new release, with my credit.
    Thanks.
    Here is a patch I wrote to add a new feature. With this patch user can chose to show in the slider only posts with featured image. Is just one more options, and these are just a few lines. Decision is up to you.

    
    diff -ruN ./recent-posts-flexslider-orig/recent-posts-flexslider.php ./recent-posts-flexslider/recent-posts-flexslider.php
    --- ./recent-posts-flexslider-orig/recent-posts-flexslider.php	2020-01-19 13:45:14.000000000 +0100
    +++ ./recent-posts-flexslider/recent-posts-flexslider.php	2020-01-20 23:06:08.519513743 +0100
    @@ -92,6 +92,7 @@
     		$post_title       = $instance['post_title'];
     		$post_excerpt     = $instance['post_excerpt'];
     		$post_link        = $instance['post_link'];
    +		$only_thumb_post  = $instance['only_thumb_post'];
     
     		echo $before_widget;
     
    @@ -135,6 +136,7 @@
     		$instance['post_title']       = isset( $new_instance['post_title'] ) ? 'true' : 'false';
     		$instance['post_excerpt']     = isset( $new_instance['post_excerpt'] ) ? 'true' : 'false';
     		$instance['post_link']        = isset( $new_instance['post_link'] ) ? 'true' : 'false';
    +		$instance['only_thumb_post']  = isset( $new_instance['only_thumb_post'] ) ? 'true' : 'false';
     
     		return $instance;
     
    @@ -163,6 +165,7 @@
     			'post_excerpt'     => 'true',
     			'excerpt_length'   => 20,
     			'post_link'        => 'true',
    +			'only_thumb_post'  => 'true',
     		);
     		$instance = wp_parse_args( (array) $instance, $defaults );
     
    diff -ruN ./recent-posts-flexslider-orig/views/admin.php ./recent-posts-flexslider/views/admin.php
    --- ./recent-posts-flexslider-orig/views/admin.php	2020-01-19 13:45:14.000000000 +0100
    +++ ./recent-posts-flexslider/views/admin.php	2020-01-20 23:01:38.427302734 +0100
    @@ -112,6 +112,7 @@
     				} else {
     					if ( isset( $_wp_additional_image_sizes ) && isset( $_wp_additional_image_sizes[ $s ] ) ) {
     						$sizes[ $s ] = array( $_wp_additional_image_sizes[ $s ]['width'], $_wp_additional_image_sizes[ $s ]['height'] );
    +
     					}
     				}
     			}
    @@ -165,4 +166,9 @@
     		<input id="<?php echo esc_attr( $this->get_field_id( 'excerpt_length' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'excerpt_length' ) ); ?>" value="<?php echo esc_attr( $instance['excerpt_length'] ); ?>" type="text" />
     	</div>
     
    +	<div class="checkbox-wrap">
    +		<input class="checkbox" type="checkbox" <?php checked( $instance['only_thumb_post'], 'true' ); ?> id="<?php echo esc_attr( $this->get_field_id( 'only_thumb_post' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'only_thumb_post' ) ); ?>" value="true" />
    +		<label for="<?php echo esc_attr( $this->get_field_id( 'only_thumb_post' ) ); ?>"><?php esc_attr_e( 'Only posts with featured image', 'only_thumb_post' ); ?></label>
    +	</div>
    +	
     </div>
    diff -ruN ./recent-posts-flexslider-orig/views/display.php ./recent-posts-flexslider/views/display.php
    --- ./recent-posts-flexslider-orig/views/display.php	2019-02-21 14:01:22.000000000 +0100
    +++ ./recent-posts-flexslider/views/display.php	2020-01-20 23:02:45.787565897 +0100
    @@ -28,6 +28,10 @@
     	'ignore_sticky_posts' => true,
     );
     
    +if (esc_attr( $only_thumb_post ) == 'true') {
    +	$flex_args['meta_query'] = array( array ( 'key' => '_thumbnail_id', 'compare' => 'EXISTS', ));
    +}
    +
     $flex_query = new WP_Query( $flex_args );
     
     // Call class to display slider
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Giuseppe

    (@mociofiletto)

    Before to push this patch, please remember to generate a new .pot file (I added one string).
    Thanks

    Plugin Author david wolfpaw

    (@wolfpaw)

    Thanks for the suggestion, that’s a good idea. I just incorporated it in v2.2.0 of the plugin.

    Note if you haven’t seen it yet, if there isn’t a featured image (and the new option is not set to true), it’ll look for the first image in the post to use for the slider.

    Thread Starter Giuseppe

    (@mociofiletto)

    Thanks David,
    I saw the feature to look for the first image in a post. It can be usefull but it can be a problem if you use a specific image size for slider that is not the one you use for the first image in post.
    Thanks for merging (and for better formatting).
    Bye

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Patch for new feature: show only posts with featured image’ is closed to new replies.