这将创建一个元盒,供您输入视频代码。
//Creating a MetaBox for Posts to enter Video Code.
add_action(\'add_meta_boxes\',\'video_meta_box\');
function video_meta_box(){
add_meta_box(\'video_box_id\', \'Enter Video \' , \'video_box_cb\',\'post\',\'normal\',\'default\');
}
function video_box_cb($post){
$value = get_post_meta($post->ID,\'video_box\',true);
echo \'<textarea rows="4" cols="50" id="video_box", name="video_box">\';
echo $value;
echo \'</textarea>\';
}
add_action(\'save_post\',\'save_video_box\');
function save_video_box($post_id){
$box_data = $_POST[\'video_box\'];
update_post_meta($post_id,\'video_box\',$box_data);
}
使用此代码在主题中呈现此代码。
<?php
$custom_values = get_post_custom($post->ID);
echo \'<p> Video CODE: \'.$custom_values[\'video_box\'][0].\'</p>\';
?>