好的,使用这个“插件”(JareDatch). 它就像一个符咒。
add_filter( \'cmb_meta_boxes\', \'cmb_sample_metaboxes\' ); /** * Define the metabox and field configurations. ** @param array $meta_boxes * @return array */ function cmb_sample_metaboxes( array $meta_boxes ) {
// Start with an underscore to hide fields from custom fields list
$prefix = \'_cmb_\';
$meta_boxes[] = array(
\'id\' => \'appstore_link\',
\'title\' => \'App Store\',
\'pages\' => array( \'apps\', ), // Post type
\'context\' => \'normal\',
\'priority\' => \'high\',
\'show_names\' => true, // Show field names on the left
\'fields\' => array(
array(
\'name\' => \'App Store\',
\'desc\' => \'field description (optional)\',
\'id\' => $prefix . \'app_store_link\',
\'type\' => \'text\',
),
)
);
// Add other metaboxes as needed
return $meta_boxes;}
add_action( \'init\', \'cmb_initialize_cmb_meta_boxes\', 9999 ); function cmb_initialize_cmb_meta_boxes() {
if ( ! class_exists( \'cmb_Meta_Box\' ) )
require_once \'init.php\';}
并在主题中使用以下内容:
<?php if ( get_post_meta($post->ID, \'_cmb_app_store_link\', true) ) : ?>
<a href="<?php echo get_post_meta($post->ID, \'_cmb_app_store_link\', true) ?>">
<img src="source.png" src="<?php echo get_post_meta($post->ID, \'_cmb_app_store_link\', true) ?>" alt="<?php the_title(); ?>" />
</a>