mirror of
https://github.com/10h30/display-featured-image-genesis.git
synced 2026-07-11 18:46:03 +09:00
Add setting to use term/cpt images as fallbacks for archive thumbnails
This commit is contained in:
@@ -85,10 +85,11 @@ class Display_Featured_Image_Genesis_Helper {
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public function do_checkbox( $args ) {
|
||||
$setting = isset( $this->displaysetting[ $args['setting'] ] ) ? $this->displaysetting[ $args['setting'] ] : 0;
|
||||
printf( '<input type="hidden" name="displayfeaturedimagegenesis[%s]" value="0" />', esc_attr( $args['setting'] ) );
|
||||
printf( '<label for="displayfeaturedimagegenesis[%1$s]"><input type="checkbox" name="displayfeaturedimagegenesis[%1$s]" id="displayfeaturedimagegenesis[%1$s]" value="1" %2$s class="code" />%3$s</label>',
|
||||
esc_attr( $args['setting'] ),
|
||||
checked( 1, esc_attr( $this->displaysetting[ $args['setting'] ] ), false ),
|
||||
checked( 1, esc_attr( $setting ), false ),
|
||||
esc_attr( $args['label'] )
|
||||
);
|
||||
$this->do_description( $args['setting'] );
|
||||
|
||||
@@ -354,4 +354,38 @@ class Display_Featured_Image_Genesis_Output {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* If there is no image to use for the post thumbnail in archives,
|
||||
* optionally use the term or post type image as a fallback instead.
|
||||
*
|
||||
* @param $defaults
|
||||
*
|
||||
* @return mixed
|
||||
* @since 2.5.0
|
||||
*/
|
||||
public function change_thumbnail_fallback( $defaults ) {
|
||||
if ( ! isset( $this->displaysetting['thumbnails'] ) || ! $this->displaysetting['thumbnails'] ) {
|
||||
return $defaults;
|
||||
}
|
||||
remove_action( 'genesis_entry_content', 'display_featured_image_genesis_add_archive_thumbnails', 5 );
|
||||
$args = array(
|
||||
'post_mime_type' => 'image',
|
||||
'post_parent' => get_the_ID(),
|
||||
'post_type' => 'attachment',
|
||||
);
|
||||
$attached_images = get_children( $args );
|
||||
if ( $attached_images ) {
|
||||
return $defaults;
|
||||
}
|
||||
$image_id = display_featured_image_genesis_get_term_image_id();
|
||||
if ( empty( $image_id ) ) {
|
||||
$image_id = display_featured_image_genesis_get_cpt_image_id();
|
||||
}
|
||||
if ( $image_id ) {
|
||||
$defaults['fallback'] = $image_id;
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,6 +100,7 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
|
||||
'move_excerpts' => 0,
|
||||
'is_paged' => 0,
|
||||
'feed_image' => 0,
|
||||
'thumbnails' => 0,
|
||||
);
|
||||
|
||||
return get_option( 'displayfeaturedimagegenesis', $defaults );
|
||||
@@ -198,6 +199,13 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
|
||||
'section' => 'main',
|
||||
'args' => array( 'setting' => 'feed_image', 'label' => __( 'Optionally, add the featured image to your RSS feed.', 'display-featured-image-genesis' ) ),
|
||||
),
|
||||
array(
|
||||
'id' => 'thumbnails',
|
||||
'title' => __( 'Archive Thumbnails?', 'display-featured-image-genesis' ),
|
||||
'callback' => 'do_checkbox',
|
||||
'section' => 'main',
|
||||
'args' => array( 'setting' => 'thumbnails', 'label' => __( 'Use term/post type fallback images for content archives?', 'display-featured-image-genesis' ) ),
|
||||
),
|
||||
);
|
||||
|
||||
if ( $this->post_types ) {
|
||||
|
||||
@@ -111,6 +111,7 @@ class Display_Featured_Image_Genesis {
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
||||
add_filter( 'plugin_action_links_' . DISPLAYFEATUREDIMAGEGENESIS_BASENAME, array( $this, 'add_settings_link' ) );
|
||||
add_filter( 'displayfeaturedimagegenesis_get_setting', array( $this->settings, 'get_display_setting' ) );
|
||||
add_filter( 'genesis_get_image_default_args', array( $this->output, 'change_thumbnail_fallback' ) );
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user