我正在使用Wordpress的时间线快速插件。我正在尝试添加自定义图标,但它无法正常工作。我正在使用它:https://gist.github.com/EvanHerman/6bbc8de82f34b4cb3c5c但该字段未显示。
<?php
/*
Plugin Name: Timeline Express Custom Icon Filter Test
*/
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, $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
}