Last active
May 17, 2016 21:51
-
-
Save EvanHerman/ba29e4941be52042ef57 to your computer and use it in GitHub Desktop.
Use the announcement image as the icon - Props Pete Nelson
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 Custom Icon Filter Test | |
* Note: Requires Timeline Express v1.2 or later. | |
* The following code should be placed in the bottom of your active themes functions.php file. | |
*/ | |
add_filter( 'timeline-express-custom-icon-html', 'pn_timeline_express_custom_icon_html_test', 10, 3 ); | |
function pn_timeline_express_custom_icon_html_test( $html, $post_id, $timeline_express_options ) { | |
$custom_png_icon = get_post_meta( $post_id, '_custom_png_icon', true ); | |
if ( ! $custom_png_icon ) { | |
return $html; | |
} else { | |
$image_html = '<img class="custom-image" src="' .$custom_png_icon . '" />'; | |
} | |
if ( empty( $image_html) ) { | |
return $html; | |
} | |
// capture custom image HTML for the icon | |
ob_start(); | |
if ( $timeline_express_options['read-more-visibility'] != 0 ) { ?> | |
<a class="cd-timeline-icon-link" href="<?php echo get_the_permalink( $post_id ); ?>"> | |
<div class="cd-timeline-img cd-picture cd-timeline-png"> | |
<?php echo $image_html; ?> | |
</div> <!-- cd-timeline-img --> | |
</a> | |
<?php } else { ?> | |
<div class="cd-timeline-img cd-picture cd-timeline-png"> | |
<?php echo $image_html; ?> | |
</div> <!-- cd-timeline-img --> | |
<?php } | |
$html = ob_get_contents(); | |
ob_end_clean(); | |
return $html; | |
} | |
add_filter( 'timeline_express_custom_fields' , 'add_custom_timeline_express_field' ); | |
function add_custom_timeline_express_field( $custom_fields ) { | |
$custom_fields = array( | |
array( | |
'name' => __( 'Example Text Field', 'timeline-express' ), | |
'desc' => __( 'this is an example user defined text field.', 'timeline-express' ), | |
'id' => '_custom_png_icon', | |
'type' => 'file', | |
), | |
); | |
return $custom_fields; | |
} | |
add_action( 'wp_footer', 'pn_timeline_express_custom_icon_html_footer_css' ); | |
function pn_timeline_express_custom_icon_html_footer_css() { | |
?> | |
<style> | |
#primary .cd-timeline-img { | |
border-radius: 0; | |
box-shadow: none; | |
} | |
#primary .cd-timeline-img.cd-picture { | |
background: none; | |
border: none; | |
} | |
#primary .cd-timeline-img img { | |
width: 60px; | |
height: 60px; | |
margin-left: -30px; | |
margin-top: -30px; | |
height: auto; | |
} | |
</style> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment