![](/img/trans.png)
[英]How do i add an custom post type to a new role created by the Members plugin for wordpress
[英]How do I modify the New Post form in WordPress from a plugin?
我將解釋我正在創建的內容,以便您可以輕松理解我的問題。 我正在制作一個插件,可讓您將“餐廳菜單”添加到您的網站。 我目前有自定義管理儀表板菜單鏈接,如果您想將菜品添加到餐廳菜單,可將您帶到新的帖子頁面。 我想修改“新帖子”頁面,以便有一個價格字段和一個縮略圖上傳器,以及將該頁面的標題從“添加新頁面”更改為“添加新菜”。 我創建了一個自定義帖子類型“ dish”,並且只希望在帖子類型為dish時進行這些更改。 帖子類型為盤時,如何在“添加新頁面”表單中添加更改? 到目前為止,這是我的插件代碼(PS),這是我的第一個插件!
<?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,
)
);
}
要更改UI中的標簽,請參見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' );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.