我已经构建了一个基本的元框,并将其包含在我的函数中。php。
当前代码:
add_action( \'admin_print_styles-post-new.php\', \'portfolio_admin_style\', 11 );
add_action( \'admin_print_styles-post.php\', \'portfolio_admin_style\', 11 );
function portfolio_admin_style() {
global $post_type;
if( \'portfolio\' == $post_type )
wp_enqueue_style( \'portfolio-admin-style\', get_stylesheet_directory_uri() . \'/styles/portfolio-admin.css\' );
}
add_action(\'init\', \'create_portfolio\');
function create_portfolio() {
$portfolio_args = array(
\'label\' => __(\'Portfolio\'),
\'singular_label\' => __(\'Portfolio\'),
\'public\' => true,
\'show_ui\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'rewrite\' => true,
\'supports\' => array(\'title\', \'editor\', \'thumbnail\')
);
register_post_type(\'portfolio\',$portfolio_args);
}
// Input fields
add_action("admin_init", "add_portfolio");
add_action(\'save_post\', \'update_website_url\');
function add_portfolio(){
add_meta_box("portfolio_details", "Portfolio Options", "portfolio_options", "portfolio", "normal", "low");
}
function portfolio_options(){
global $post;
$custom = get_post_custom($post->ID);
$website_url = $custom["website_url"][0];
$port_excerpt = $custom["port_excerpt"][0];
?>
<div id="portfolio-options">
<label>Website URL:</label><input name="website_url" value="<?php echo $website_url; ?>" />
<label>Excerpt:</label><input name="port_excerpt" value="<?php echo $port_excerpt; ?>" />
</div><!--end portfolio-options-->
<?php
}
function update_website_url(){
global $post;
update_post_meta($post->ID, "website_url", $_POST["website_url"]);
update_post_meta($post->ID, "port_excerpt", $_POST["port_excerpt"]);
}
add_filter("manage_edit-portfolio_columns", "portfolio_edit_columns");
add_action("manage_posts_custom_column", "portfolio_columns_display");
function portfolio_edit_columns($portfolio_columns){
$portfolio_columns = array(
"cb" => "<input type=\\"checkbox\\" />",
"title" => "Project Title",
"description" => "Description",
);
return $portfolio_columns;
}
function portfolio_columns_display($portfolio_columns){
switch ($portfolio_columns)
{
case "description":
the_excerpt();
break;
}
}
问题是样式表没有改变自定义元框的样式!我从代码中的正确目录调用了样式表。如果有必要,这将与自定义帖子模板一起使用。
最合适的回答,由SO网友:Joshua Abenazer 整理而成
从上述代码中删除wp\\u enqueue\\u样式行,并将其替换为:
add_action( \'admin_print_styles-post-new.php\', \'portfolio_admin_style\', 11 );
add_action( \'admin_print_styles-post.php\', \'portfolio_admin_style\', 11 );
function portfolio_admin_style() {
global $post_type;
if( \'portfolio\' == $post_type )
wp_enqueue_style( \'portfolio-admin-style\', get_stylesheet_directory_uri() . \'/css/portfolio-admin.css\' );
}
最好将管理面板的样式放在一个单独的文件中,比如在theme\\u目录/css/portfolio admin中。css作为前端样式可能与管理样式冲突。