2016-05-05 19 views
0
add_filter('rwmb_meta_boxes', 'your_prefix_meta_boxes'); 
function your_prefix_meta_boxes($meta_boxes) { 
    $meta_boxes[] = array(
     'title'  => __('Test Meta Box', 'textdomain'), 
     'post_types' => 'post', 
     'fields'  => array(
      array(
       'id' => 'name', 
       'name' => __('Name', 'textdomain'), 
       'type' => 'text', 
      ), 
      array(
       'id'  => 'gender', 
       'name' => __('Gender', 'textdomain'), 
       'type' => 'radio', 
       'options' => array(
        'm' => __('Male', 'textdomain'), 
        'f' => __('Female', 'textdomain'), 
       ), 
      ), 
      array(
       'id' => 'email', 
       'name' => __('Email', 'textdomain'), 
       'type' => 'email', 
      ), 
     ), 
    ); 
    return $meta_boxes; 
} 

我把pud這個代碼放在我的function.php中,我在添加新的帖子只是添加meta box。我的網頁上也需要meta box。請幫助我添加meta框只出現在添加新帖子中沒有出現在頁面

+0

' 'post_types'=>陣列( '後', '頁面'),' –

+0

如何爲特定頁面 –

+0

https://metabox.io/docs/meta要這樣做-box-include-exclude/ –

回答

0

您應該選擇頁面上可用的鉤子之一併在其中添加您的功能。例如使用page_template鉤:

add_filter('page_template', 'your_prefix_meta_boxes'); 
+0

我的模板名稱是homepage1 我應該試試這個爲 'add_filter('homepage1','your_prefix_meta_boxes');' –

+0

沒有'homepage1'鉤子。你應該檢查你的帖子type = page有哪些鉤子可用。另外,使用Dr.Molle的建議:更改'post_types'=> array('post','page') – Taras

+0

可以請你幫我一些更多的wordpress im有一些困難 –

相關問題