2016-01-13 103 views
0

我将解释我正在创建的内容,以便您轻松理解我的问题。我正在制作一个插件,让你在你的网站上添加一个餐厅菜单。我目前有自定义管理仪表板菜单链接,如果你想添加一道菜到餐馆菜单,你可以进入新的发布页面。我想修改“新文章”页面,以便有价格字段和缩略图上传器,并将页面标题从“添加新页面”更改为“添加新菜单”。我创建了一个自定义帖子类型的“碟子”,我只希望在帖子类型是碟子时发生这些更改。如果帖子类型是碟子,我怎样才能在“添加新页面”表单中添加更改?这是我的插件代码到目前为止...(P.S.)这是我的第一个插件!如何从插件修改WordPress中的新帖子表单?

<?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

要更改标签的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');