diff --git a/README.md b/README.md index 9a9f17c..521c510 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,15 @@ This plugin works within the Genesis Framework, to display your post/page featur ## Description This plugin takes a different approach to how we use and display featured images for posts and pages. Instead of simply reusing an image which already exists in the post/page content, the plugin anticipates that you will want to use lovely large images for your featured images, but to do so intelligently. Depending on what you upload, the plugin will: -* display the image as a backstretch (screen width) image if the image is wider than your site's Large Media Setting. + +* display the image as a _backstretch_ (screen width) image if the image is wider than your site's Large Media Setting. * display the image above your post/page content, centered and up to the width of the content, if your image is larger than your Medium Media Setting, and less than or equal to your Large Media Setting. -* display nothing if your featured image width is less than or equal to your Medium Media Setting. -* display nothing if your featured image is already displayed in your content (the original image, not a resized version). +* display _nothing_ if your featured image width is less than or equal to your Medium Media Setting. +* display _nothing_ if your featured image is already displayed in your content (the original image, not a resized version). + +__New in 1.2.0:__ you can now use the WordPress Customizer to set a _Default Featured Image_ to be used site-wide. This image will be used on any post/page/custom post type which does not have a featured image set. + +_Note: This plugin works with the Genesis Framework and child themes only._ ## Requirements * WordPress 3.8, tested up to 4.0 @@ -44,6 +49,9 @@ Then go to your Plugins screen and click __Activate__.  __Screenshot of a page using the Backstretch Featured Image.__ + +__Use the WordPress Customizer to set a Default Featured Image.__ + ## Frequently Asked Questions ### How do I stop the featured image action from showing on my custom post types? @@ -59,15 +67,18 @@ function rgc_skip_post_types( $post_types ) { return $post_types; } ``` + +It seems that you can also include [conditional tags](http://codex.wordpress.org/Conditional_Tags) in the above, eg `$post_types[] = is_front_page();` to stop the featured image from displaying. This is most helpful if you have set a default featured image in the Customizer. + ### The backstretch image is a little too tall. -If you do not want the height of the backstretch image to be quite the height of the user's window, you can reduce it by just a hair. Go to Settings > Media and change the 'Reduction amount' number from the default of 0. The higher this number is, the shorter your image will be. Feel free to experiment, as no images are harmed by changing this number. +If you do not want the height of the backstretch image to be quite the height of the user's window, you can reduce it by just a hair. Go to Settings > Media and change the 'Height' number from the default of 0. The higher this number is, the shorter your image will be. Feel free to experiment, as no images are harmed by changing this number. -Additionally/alternatively, you could set a max-height for the backstretch image via css: +Additionally/alternatively, you could set a max-height for the backstretch image area via css: ```css -.backstretch { - max-height: 700px; +.big-leader { + max-height: 700px !important; } ``` ## Credits @@ -76,6 +87,10 @@ Additionally/alternatively, you could set a max-height for the backstretch image ## Changelog +###1.2.0 +* new feature: default featured image to display if no image is set +* better method naming/organization + ###1.1.3 * output is now properly managed to show only on single posts/pages and home page, not archives diff --git a/assets/screenshot-2.jpg b/assets/screenshot-2.jpg new file mode 100644 index 0000000..4ba8841 Binary files /dev/null and b/assets/screenshot-2.jpg differ diff --git a/display-featured-image-genesis.php b/display-featured-image-genesis.php index dee1319..216a1d6 100644 --- a/display-featured-image-genesis.php +++ b/display-featured-image-genesis.php @@ -12,7 +12,7 @@ * Plugin Name: Display Featured Image for Genesis * Plugin URI: http://github.com/robincornett/display-featured-image-genesis/ * Description: This plugin requires the Genesis Framework. It varies the display of the post or page featured image, depending on size. - * Version: 1.1.3 + * Version: 1.2.0 * Author: Robin Cornett * Author URI: http://robincornett.com * License: GPL-2.0+ diff --git a/includes/class-displayfeaturedimagegenesis-customizer.php b/includes/class-displayfeaturedimagegenesis-customizer.php new file mode 100644 index 0000000..e5f242b --- /dev/null +++ b/includes/class-displayfeaturedimagegenesis-customizer.php @@ -0,0 +1,57 @@ +statuses = array( '' => __( 'No Image', 'display-featured-image-genesis' ) ); + + parent::__construct( $manager, $id, $args ); + + $this->add_tab( 'upload-new', __( 'Upload New', 'display-featured-image-genesis' ), array( $this, 'tab_upload_new' ) ); + $this->add_tab( 'uploaded', __( 'Uploaded', 'display-featured-image-genesis' ), array( $this, 'tab_uploaded' ) ); + + if ( $this->setting->default ) + $this->add_tab( 'default', __( 'Default', 'display-featured-image-genesis' ), array( $this, 'tab_default_background' ) ); + + // Early priority to occur before $this->manager->prepare_controls(); + add_action( 'customize_controls_init', array( $this, 'prepare_control' ), 5 ); + } + +} + + global $wp_customize; + + $wp_customize->add_section( 'displayfeaturedimage-settings', array( + 'title' => __( 'Default Featured Image', 'display-featured-image-genesis' ), + 'priority' => 105, + ) ); + + $wp_customize->add_setting( 'displayfeaturedimage_default', array( + 'type' => 'option', + ) ); + + $wp_customize->add_control( new Display_Featured_Image_Genesis_Customizer( $wp_customize, 'displayfeaturedimage_default', array( + 'label' => __( 'Display Featured Image for Genesis', 'display-featured-image-genesis' ), + 'description' => __( 'You may set a default image to be used as the backstretch or large featured image if no image is selected for the post/page.', 'display-featured-image-genesis' ), + 'section' => 'displayfeaturedimage-settings', + 'settings' => 'displayfeaturedimage_default', + ) ) ); diff --git a/includes/class-displayfeaturedimagegenesis-output.php b/includes/class-displayfeaturedimagegenesis-output.php index 8a7a9db..1dbecbd 100644 --- a/includes/class-displayfeaturedimagegenesis-output.php +++ b/includes/class-displayfeaturedimagegenesis-output.php @@ -33,13 +33,29 @@ class Display_Featured_Image_Genesis_Output { protected function get_image_variables() { $item = new stdClass(); global $post; - if ( is_home() ) { - $postspage = get_option( 'page_for_posts' ); + $fallback = get_option( 'displayfeaturedimage_default' ); + $postspage = get_option( 'page_for_posts' ); + $postspage_image = get_post_thumbnail_id( $postspage ); + + // Set Featured Image Source + if ( is_home() && !empty( $postspage_image ) ) { $item->original = wp_get_attachment_image_src( get_post_thumbnail_id( $postspage ), 'original' ); } + elseif ( !empty( $fallback ) && !has_post_thumbnail() ) { + $fallback_id = $this->get_image_id( $fallback ); + $item->original = wp_get_attachment_image_src( $fallback_id, 'original' ); + } else { $item->original = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'original' ); } + + // Set Post/Page Title + if ( is_home() ) { + $item->title = get_post( $postspage )->post_title; + } + else { + $item->title = get_the_title(); + } $item->large = get_option( 'large_size_w' ); $item->medium = get_option( 'medium_size_w' ); $item->reduce = get_option( 'displayfeaturedimage_less_header', 0 ); @@ -68,21 +84,26 @@ class Display_Featured_Image_Genesis_Output { public function load_scripts() { $item = $this->get_image_variables(); - if ( ( has_post_thumbnail() && $item->content === false ) || is_home() ) { + if ( ( !empty( $item->original ) && $item->content === false ) || is_home() ) { wp_enqueue_style( 'displayfeaturedimage-style', plugins_url( 'includes/css/display-featured-image-genesis.css', dirname( __FILE__ ) ), array(), 1.0 ); - add_action( 'genesis_before', array( $this, 'do_featured_image' ) ); - - if ( ( $item->original[1] ) > $item->large ) { + if ( ( ( $item->original[1] ) > $item->large ) ) { wp_enqueue_script( 'displayfeaturedimage-backstretch', plugins_url( '/includes/js/backstretch.js', dirname( __FILE__ ) ), array( 'jquery' ), '1.0.0' ); wp_enqueue_script( 'displayfeaturedimage-backstretch-set', plugins_url( '/includes/js/backstretch-set.js', dirname( __FILE__ ) ), array( 'jquery', 'displayfeaturedimage-backstretch' ), '1.0.0' ); wp_localize_script( 'displayfeaturedimage-backstretch-set', 'BackStretchVars', array( - 'src' => $item->original[0], + 'src' => $item->original[0], 'height' => esc_attr( $item->reduce ) )); + add_action( 'genesis_after_header', array( $this, 'do_backstretch_image_title' ) ); + + } + + elseif ( ( $item->original[1] <= $item->large ) && ( $item->original[1] > $item->medium ) ) { + add_action( 'genesis_before_entry', array( $this, 'do_large_image' ) ); // HTML5 + add_action( 'genesis_before_post', array( $this, 'do_large_image' ) ); // XHTML } } } @@ -98,11 +119,11 @@ class Display_Featured_Image_Genesis_Output { $item = $this->get_image_variables(); - if ( $item->content === false ) { - if ( ( has_post_thumbnail() || is_home() ) && $item->original[1] > $item->large ) { + if ( !empty( $item->original ) && $item->content === false ) { + if ( $item->original[1] > $item->large ) { $classes[] = 'has-leader'; } - elseif ( has_post_thumbnail() && ( ( $item->original[1] <= $item->large ) && ( $item->original[1] > $item->medium ) ) ) { + elseif ( ( $item->original[1] <= $item->large ) && ( $item->original[1] > $item->medium ) ) { $classes[] = 'large-featured'; } } @@ -110,35 +131,12 @@ class Display_Featured_Image_Genesis_Output { } /** - * do the featured image + * backstretch image title (for images which are larger than Media Settings > Large ) * @return image * * @since 1.0.0 */ - public function do_featured_image() { - global $post; - - $item = $this->get_image_variables(); - - if ( $item->content === false ) { - if ( $item->original[1] > $item->large ) { - add_action( 'genesis_after_header', array( $this, 'do_backstretch_image' ) ); - } - elseif ( ( $item->original[1] <= $item->large ) && ( $item->original[1] > $item->medium ) ) { - add_action( 'genesis_before_entry', array( $this, 'do_large_image' ) ); // HTML5 - add_action( 'genesis_before_post', array( $this, 'do_large_image' ) ); // XHTML - } - } - - } - - /** - * backstretch image (for images which are larger than Media Settings > Large ) - * @return image - * - * @since 1.0.0 - */ - public function do_backstretch_image() { + public function do_backstretch_image_title() { $item = $this->get_image_variables(); @@ -148,14 +146,7 @@ class Display_Featured_Image_Genesis_Output { } echo '