我将解释我正在创建的内容,以便您轻松了解我的问题。我正在制作一个插件,让你在网站上添加一个餐厅菜单。我目前有自定义管理仪表板菜单链接,如果您想在餐厅菜单中添加菜肴,可以将您带到新的帖子页面。我想修改“新帖子”页面,以便有一个价格字段和一个缩略图上传器,以及将页面标题从“添加新页面”更改为“添加新菜”。我创建了一个自定义帖子类型的“菜”,我只希望这些更改发生在帖子类型是菜。当帖子类型为菜时,如何将更改添加到“添加新页面”表单?这是我到目前为止的插件代码...(P.S。)这是我的第一个插件!
<?php
/*
Plugin Name: HeadChef
Plugin URI: http://google.com
Description: Adds functionality for the restaurant's menu
Author: John Smith
Version: Alpha
Author URI: http://google.com
*/
add_action('admin_menu', 'hc_add_menu_items');
function hc_add_menu_items() {
// $page_title, $menu_title, $capability, $menu_slug, $callback_function
add_posts_page(__('Restaurant Menu'), __('My Menus'), 'read', 'edit.php?post_type=dish');
}
add_action( 'init', 'hc_create_post_type' );
function hc_create_post_type(){
register_post_type( 'dish',
array(
'labels' => array(
'name' => __( 'Menu Dish' ),
'singular_name' => __( 'Dish' )
),
'public' => true,
'has_archive' => true,
)
);
}
答案 0 :(得分:0)
要更改用户界面中的标签,请参阅register_post_type()
的参数,例如:
$labels = array(
'name' => _x( 'Menu dish' ),
'singular_name' => _x( 'Dish' ),
'add_new_item' => __( 'Add new dish' ),
'new_item' => __( 'New dish' ),
// ...
);
您可以使用add_meta_box()
function myplugin_add_meta_box() {
// add here which for post types you want this box
$screens = array( 'dish' );
add_meta_box(
'myplugin_sectionid',
__( 'My Post Section Title', 'myplugin_textdomain' ),
'myplugin_meta_box_callback',
$screens
);
}
add_action( 'add_meta_boxes', 'myplugin_add_meta_box' );