Created
May 18, 2016 21:54
-
-
Save EvanHerman/233ed0ec8920abefc3841d3d93dddcc1 to your computer and use it in GitHub Desktop.
Use a different image on the single announcement page, than what is used on the timeline.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Timeline Express Add Custom Metabox | |
* @param array $options Array of options for Timeline Express. | |
*/ | |
function define_custom_excerpt_metabox( $options ) { | |
$announcement_custom_metabox = new_cmb2_box( array( | |
'id' => 'custom_meta', | |
'title' => __( 'Additional Announcement Meta', 'text-domain' ), | |
'object_types' => array( 'te_announcements' ), // Post type | |
'context' => 'advanced', | |
'priority' => 'high', | |
'show_names' => true, // Show field names on the left | |
) ); | |
// Container class | |
$announcement_custom_metabox->add_field( array( | |
'name' => __( 'Single Featured Image', 'text-domain' ), | |
'desc' => __( 'This is the image used on the single announcement page.', 'text-domain' ), | |
'id' => 'announcement_single_image', | |
'type' => 'file', | |
) ); | |
} | |
add_action( 'timeline_express_metaboxes', 'define_custom_excerpt_metabox' ); | |
/** | |
* Hook in and display our new featured image (if set) above the content | |
* - Timeline Express Single Announcement Images | |
*/ | |
function replace_default_timeline_express_single_image( $image, $post_id ) { | |
$post = get_post( $post_id ); | |
if ( is_single() && timeline_express_get_custom_meta( $post_id, 'announcement_single_image', true ) ) { | |
return wp_get_attachment_image( | |
get_post_meta( $post_id, 'announcement_single_image_id', true ), | |
'medium', | |
false, | |
array( | |
'title' => get_the_title( $post ), | |
'class' => 'announcement-banner-image', | |
'style' => 'width: auto', | |
) | |
); | |
} else { | |
return $image; | |
} | |
} | |
add_filter( 'timeline_express_image', 'replace_default_timeline_express_single_image', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment