Patch for new feature: show only posts with featured image
-
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)
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.