我设法让“车辆管理员”部分在左侧加载,这样我就可以创建自定义帖子类型了,但是我无法显示元框以显示该帖子类型的自定义信息(如果这很有意义。)
这是我的vehicle-manager.php:
<?php
add_action('init', 'vehicle_manager_register');
function vehicle_manager_register()
{
//Arguments to create post type.
$args = array(
'label' => __('Vehicle Manager'),
'singular_label' => __('Vehicle'),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => true,
'has_archive' => true,
'supports' => array(
'title',
'editor',
'thumbnail'
),
'rewrite' => array(
'slug' => 'vehicles',
'with_front' => false
)
);
//Register type and custom taxonomy for type.
register_post_type('vehicle', $args);
register_taxonomy("vehicle-type", array(
"vehicles"
), array(
"hierarchical" => true,
"label" => "Vehicle Types",
"singular_label" => "Vehicle Type",
"rewrite" => true,
"slug" => 'vehicle-type'
));
}
//Begin custom fields
if (function_exists('add_theme_support')) {
add_theme_support('post-thumbnails');
set_post_thumbnail_size(220, 150);
add_image_size('storefront', 800, 600, true);
}
add_action("admin_init", "vehicle_manager_add_meta");
function vehicle_manager_add_meta()
{
add_meta_box("vehicle-meta", "Vehicle Options", "vehicle_manager_meta_options", "vehicles", "normal", "high");
}
//Start of actual custom fields
function vehicle_manager_meta_options()
{
global $post;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return $post_id;
$custom = get_post_custom($post->ID);
$make = $custom["make"][0];
$model = $custom["model"][0];
$year = $custom["year"][0];
$mileage = $custom["mileage"][0];
$engine = $custom["engine"][0];
$colour = $custom["colour"][0];
$price = $custom["price"][0];
$uspa = $custom["uspa"][0];
$uspb = $custom["uspb"][0];
$uspc = $custom["uspc"][0];
?>
<style type="text/css">
<?php
include('vehicle-manager.css');
?>
</style>
<div class="vehicle_manager_extras">
<div><label>Make:</label><input name="make"
value="<?php
echo $make;
?>" /></div>
<div><label>Model</label><input name="model"
value="<?php
echo $model;
?>" /></div>
<div><label>Year:</label><input name="year"
value="<?php
echo $year;
?>" /></div>
<div><label>Miles:</label><input name="miles"
value="<?php
echo $miles;
?>" /></div>
<div><label>Engine:</label><input name="engine"
value="<?php
echo $engine;
?>" /></div>
<div><label>Colour:</label><input name="colour"
value="<?php
echo $colour;
?>" /></div>
<div><label>Price:</label><input name="price"
value="<?php
echo $price;
?>" /></div>
<div><label>Feature 1 (optional):</label><input name="uspa"
value="<?php
echo $uspa;
?>" /></div>
<div><label>Feature 2 (optional):</label><input name="uspb"
value="<?php
echo $uspb;
?>" /></div>
<div><label>Feature 3 (optional):</label><input name="uspc"
value="<?php
echo $uspc;
?>" /></div>
</div>
<?php
}
add_action('save_post', 'business_manager_save_extras');
function business_manager_save_extras()
{
global $post;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
//if you remove this the sky will fall on your head.
return $post_id;
} else {
update_post_meta($post->ID, "make", $_POST["make"]);
update_post_meta($post->ID, "model", $_POST["model"]);
update_post_meta($post->ID, "year", $_POST["year"]);
update_post_meta($post->ID, "miles", $_POST["miles"]);
update_post_meta($post->ID, "engine", $_POST["engine"]);
update_post_meta($post->ID, "colour", $_POST["colour"]);
update_post_meta($post->ID, "price", $_POST["price"]);
update_post_meta($post->ID, "uspa", $_POST["uspa"]);
update_post_meta($post->ID, "uspb", $_POST["uspb"]);
update_post_meta($post->ID, "uspc", $_POST["uspc"]);
}
}
这是functions.php:
<?php
require_once('vehicle-manager.php');
define('TEMPPATH', get_bloginfo('stylesheet_directory'));
define('IMAGES', TEMPPATH . "/images");
add_theme_support('nav-menus');
if (function_exists('register_nav_menus')) {
register_nav_menus(array(
'main' => 'Main Nav'
));
}
if (function_exists('register_sidebar')) {
register_sidebar(array(
'name' => __('Primary Sidebar', 'primary-sidebar'),
'id' => 'primary-widget-area',
'description' => __('The primary widget area', 'dir'),
'before_widget' => '<div class="widget">',
'after_widget' => "</div>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
));
}
16;
?>
答案 0 :(得分:0)
您正在使用帖子类型vehicles
(4th argument)注册元数据集:
add_meta_box("vehicle-meta", "Vehicle Options", "vehicle_manager_meta_options", "vehicles", "normal", "high");
当您将帖子类型注册为vehicle
(1st argument)时:
register_post_type('vehicle', $args);
当您为vehicles
而不是vehicle
启用分类时,您的分类法也不会显示:
register_taxonomy("vehicle-type", array(
"vehicles"
), array( ... ));
(另外:请尽量保持代码尽可能少,省略不相关的部分(即侧边栏内容))
答案 1 :(得分:0)
您正在记录名称为&#34; 车辆&#34;的post_type。
在分类中,您必须注册post_type&#34; 车辆&#34;没有&#34;车辆&#34;。
自定义目标还必须使用post_type&#34; 车辆&#34;没有&#34;车辆&#34;。