个性化阅读
专注于IT技术分析

特定页面模板的WP自定义元框

点击下载

我使用选项树框架创建了一个自定义元框。它显示在每个页面上。我希望它仅针对特定页面显示。我怎样才能做到这一点?

我已经将此代码编写到functions.php文件中

 add_action( 'admin_init', 'custom_meta_boxes' );

function custom_meta_boxes() {

   $latest_work = array(
'id'          => 'latest_work', 'title'       => 'latest-work Meta Box', 'desc'        => '', 'pages'       => array( 'page' ), 'context'     => 'normal', 'priority'    => 'high', 'fields'      => array(
  array(
    'label'       => 'latest-work', 'id'          => 'latest-work', 'type'        => 'text', 'desc'        => 'Tell about your latest work', 'std'         => '', 'rows'        => '', 'post_type'   => '', 'taxonomy'    => '', 'class'       => ''
  )
)  
);
ot_register_meta_box( $latest_work );
}

请告诉我我该怎么做?


#1


add_action( 'admin_menu', 'remove_post_meta_boxes' );

function remove_post_meta_boxes() {
    // lets assume blog page has the id 23
    // let's remove the meta box from blog
    if( isset($_GET['post']) && $_GET['post'] == 23 ){
        remove_meta_box( 'latest_work', 'page', 'normal' );
    }
}

查看更多信息remove_meta_box()


#2


使用以下内容。

$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;

    // checks for post/page ID for example i have added 7

    if ($post_id == '7'){
/.add_meta box code inside
}
赞(0)
未经允许不得转载:srcmini » 特定页面模板的WP自定义元框

评论 抢沙发

评论前必须登录!