Wordpress 为什么我的元盒赢了';在头版文章中没有显示?
我在任何地方都能看到它:在单篇文章、分类档案等中,但在头版文章中却看不到 我以以下方式显示元盒:Wordpress 为什么我的元盒赢了';在头版文章中没有显示?,wordpress,custom-fields,posts,meta-boxes,Wordpress,Custom Fields,Posts,Meta Boxes,我在任何地方都能看到它:在单篇文章、分类档案等中,但在头版文章中却看不到 我以以下方式显示元盒: <?php if (get_post_meta($post->ID, 'test_1', true) != '' ) { ?><?php echo get_post_meta($post->ID, 'test_1', true);?><?php } ?> 怎么了? 我做错了什么? 是否可以以不同的方式显示元框 代码如下: add_action(
<?php if (get_post_meta($post->ID, 'test_1', true) != '' ) { ?><?php echo get_post_meta($post->ID, 'test_1', true);?><?php } ?>
怎么了?
我做错了什么?
是否可以以不同的方式显示元框
代码如下:
add_action( 'init', 'create_xy_taxonomies', 0 );
function create_pc_db_taxonomies() {
register_taxonomy( 'genre', 'post', array( 'hierarchical' => false, 'label' => __('Tests', 'series'), 'query_var' => 'test', 'rewrite' => array( 'slug' => 'tests' ) ) );
$prefix = 'xy_meta_';
$meta_box = array(
'id' => 'xy-meta-box',
'title' => 'Xy tests',
'page' => 'post',
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'name' => 'Test_1',
'id' => 'test_1',
'type' => 'text',
'std' => ''
),
array(
'name' => 'Test_2',
'id' => 'test_2',
'type' => 'select',
'options' => array('','1'),
'std' => ''
),
)
);
add_action('admin_menu', 'mytheme_add_box');
function mytheme_add_box() {
global $meta_box;
add_meta_box($meta_box['id'], $meta_box['title'], 'mytheme_show_box', $meta_box['page'], $meta_box['context'], $meta_box['priority']);
}
function mytheme_show_box() {
global $meta_box, $post;
echo '<input type="hidden" name="mytheme_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />';
echo '<table class="form-table">';
foreach ($meta_box['fields'] as $field) {
$meta = get_post_meta($post->ID, $field['id'], true);
echo '<tr>',
'<th style="width:20%"><label for="', $field['id'], '">', $field['name'], '</label></th>',
'<td>';
switch ($field['type']) {
case 'text':
echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $field['std'], '" size="30" style="width:97%" />',
'<br />', $field['desc'];
break;
case 'textarea':
echo '<textarea name="', $field['id'], '" id="', $field['id'], '" cols="60" rows="4" style="width:97%">', $meta ? $meta : $field['std'], '</textarea>',
'<br />', $field['desc'];
break;
case 'select':
echo '<select name="', $field['id'], '" id="', $field['id'], '">';
foreach ($field['options'] as $option) {
echo '<option', $meta == $option ? ' selected="selected"' : '', '>', $option, '</option>';
}
echo '</select>';
break;
case 'radio':
foreach ($field['options'] as $option) {
echo '<input type="radio" name="', $field['id'], '" value="', $option['value'], '"', $meta == $option['value'] ? ' checked="checked"' : '', ' />', $option['name'];
}
break;
case 'checkbox':
echo '<input type="checkbox" name="', $field['id'], '" id="', $field['id'], '"', $meta ? ' checked="checked"' : '', ' />';
break;
}
echo '<td>',
'</tr>';
}
echo '</table>';
}
add_action('save_post', 'mytheme_save_data');
function mytheme_save_data($post_id) {
global $meta_box;
if (!wp_verify_nonce($_POST['mytheme_meta_box_nonce'], basename(__FILE__))) {
return $post_id;
}
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $post_id;
}
if ('page' == $_POST['post_type']) {
if (!current_user_can('edit_page', $post_id)) {
return $post_id;
}
} elseif (!current_user_can('edit_post', $post_id)) {
return $post_id;
}
foreach ($meta_box['fields'] as $field) {
$old = get_post_meta($post_id, $field['id'], true);
$new = $_POST[$field['id']];
if ($new && $new != $old) {
update_post_meta($post_id, $field['id'], $new);
} elseif ('' == $new && $old) {
delete_post_meta($post_id, $field['id'], $old);
}
}
}
add_操作('init','create_xy_taxonomies',0);
函数create_pc_db_taxonomies(){
注册分类法('genre','post',array('hierarchy'=>false,'label'=>'Tests','series'),'query'=>'test','rewrite'=>array('slug'=>'Tests'));
$prefix='xy_meta_';
$meta_box=数组(
'id'=>'xy元盒',
“标题”=>“Xy测试”,
'页面'=>'发布',
'上下文'=>'正常',
“优先级”=>“高”,
“字段”=>数组(
排列(
'name'=>'Test_1',
'id'=>'test_1',
'类型'=>'文本',
'std'=>'
),
排列(
'name'=>'Test_2',
'id'=>'test_2',
'类型'=>'选择',
'选项'=>数组('','1'),
'std'=>'
),
)
);
添加操作(“管理菜单”、“神话添加框”);
函数mytheme\u添加框(){
全球$meta_盒;
添加元框($meta_box['id']、$meta_box['title']、'myteme_show_box'、$meta_box['page']、$meta_box['context']、$meta_box['priority']);
}
函数mytheme\u show\u box(){
全球$meta_框,$post;
回声';
回声';
foreach($meta_框['fields']作为$field){
$meta=get_post_meta($post->ID,$field['ID'],true);
回音“,
''$field['name'],'',
'';
开关($field['type'])){
案例“文本”:
回音“,
“
,$field['desc'];
打破
案例“textarea”:
回显“”,$meta?$meta:$field['std'],“”,
“
,$field['desc'];
打破
案例“选择”:
回声';
foreach($field['options']作为$option){
回显“”,$option“”;
}
回声';
打破
“无线电”案例:
foreach($field['options']作为$option){
回显“”,$option['name'];
}
打破
案例“复选框”:
回声';
打破
}
回音“,
'';
}
回声';
}
添加操作('save_post','mysteme_save_data');
函数mytheme_保存_数据($post_id){
全球$meta_盒;
如果(!wp\u verify\u nonce($\u POST['myteme\u meta\u box\u nonce'],basename(\uuuu FILE\uuuu))){
返回$post_id;
}
if(已定义('DOING_AUTOSAVE')&&DOING_AUTOSAVE){
返回$post_id;
}
如果('page'=$\u POST['POST\u type'])){
如果(!当前用户可以($edit\u page',$post\u id)){
返回$post_id;
}
}elseif(!当前用户可以($edit\u post',$post\u id)){
返回$post_id;
}
foreach($meta_框['fields']作为$field){
$old=get_post_meta($post_id,$field['id'],true);
$new=$_POST[$field['id']];
如果($new&$new!=$old){
更新发布元($post\u id,$field['id'],$new);
}elseif(''=$new&$old){
删除后元($post\u id,$field['id'],$old);
}
}
}
您的测试将只显示自定义字段键测试的内容\u 1,是吗?多极: