我刚设置了一个自定义的帖子类型,主要是以下内容this tutorial.
我现在正在我的网站上设置东西,做了很多CSS修改之类的,每隔几分钟,帖子就会忘记自定义元框中的所有内容。
我确信我在add\\u action/update\\u post\\u meta部分中做了一些错误,但我不知道它是什么,因为我并不真正理解代码的全部功能。
无论如何,事情是这样的:
add_action(\'init\', \'portfolio_register\');
function portfolio_register() {
$labels = array(
\'name\' => _x(\'My Portfolio\', \'post type general name\'),
\'singular_name\' => _x(\'Portfolio Item\', \'post type singular name\'),
\'add_new\' => _x(\'Add New\', \'portfolio item\'),
\'add_new_item\' => __(\'Add New Portfolio Item\'),
\'edit_item\' => __(\'Edit Portfolio Item\'),
\'new_item\' => __(\'New Portfolio Item\'),
\'view_item\' => __(\'View Portfolio Item\'),
\'search_items\' => __(\'Search Portfolio\'),
\'not_found\' => __(\'Nothing found\'),
\'not_found_in_trash\' => __(\'Nothing found in Trash\'),
\'parent_item_colon\' => \'\'
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'query_var\' => true,
\'menu_icon\' => get_stylesheet_directory_uri() . \'/article16.png\',
\'rewrite\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'menu_position\' => null,
\'supports\' => array(\'title\',\'editor\',\'thumbnail\')
);
register_post_type( \'portfolio\' , $args );
}
register_taxonomy("portfolio_cat", array("portfolio"), array("hierarchical" => true, "label" => "Categories", "singular_label" => "Category", "rewrite" => true));
add_action("admin_init", "admin_init");
function admin_init(){
add_meta_box("media_meta", "Media", "media_meta", "portfolio", "normal", "low");
add_meta_box("highlights_meta", "Highlights", "highlights_meta", "portfolio", "normal", "low");
add_meta_box("main_meta", "Main", "main_meta", "portfolio", "normal", "low");
add_meta_box("tabbed_meta", "Tabbed", "tabbed_meta", "portfolio", "normal", "low");
}
function media_meta(){
global $post;
$custom = get_post_custom($post->ID);
$media_meta = $custom["media_meta"][0];
?>
<p><label>Media:</label><br />
<textarea cols="110" rows="5" name="media_meta"><?php echo $media_meta; ?></textarea></p>
<?php
}
function highlights_meta(){
global $post;
$custom = get_post_custom($post->ID);
$highlights_meta = $custom["highlights_meta"][0];
?>
<p><label>Highlights:</label><br />
<textarea cols="110" rows="5" name="highlights_meta"><?php echo $highlights_meta; ?></textarea></p>
<?php
}
function main_meta(){
global $post;
$custom = get_post_custom($post->ID);
$main_meta = $custom["main_meta"][0];
?>
<p><label>Main:</label><br />
<textarea cols="110" rows="5" name="main_meta"><?php echo $main_meta; ?></textarea></p>
<?php
}
function tabbed_meta(){
global $post;
$custom = get_post_custom($post->ID);
$tabbed_meta = $custom["tabbed_meta"][0];
?>
<p><label>Tabbed:</label><br />
<textarea cols="110" rows="5" name="tabbed_meta"><?php echo $tabbed_meta; ?></textarea></p>
<?php
}
add_action(\'save_post\', \'save_details\');
function save_details(){
global $post;
update_post_meta($post->ID, "media_meta", $_POST["media_meta"]);
update_post_meta($post->ID, "highlights_meta", $_POST["highlights_meta"]);
update_post_meta($post->ID, "main_meta", $_POST["main_meta"]);
update_post_meta($post->ID, "tabbed_meta", $_POST["tabbed_meta"]);
}
add_action("manage_posts_custom_column", "portfolio_custom_columns");
add_filter("manage_edit-portfolio_columns", "portfolio_edit_columns");
function portfolio_edit_columns($columns){
$columns = array(
"cb" => "<input type=\\"checkbox\\" />",
"title" => "Portfolio Title",
"description" => "Description",
"media_meta" => "Media",
"highlights_meta" => "Highlights",
"main_meta" => "Main",
"tabbed_meta" => "Tabbed",
"portfolio_cat" => "Portfolio Categories"
);
return $columns;
}
function portfolio_custom_columns($column){
global $post;
switch ($column) {
case "description":
the_excerpt();
break;
case "media_meta":
$custom = get_post_custom();
echo $custom["media_meta"][0];
break;
case "highlights_meta":
$custom = get_post_custom();
echo $custom["highlights_meta"][0];
break;
case "main_meta":
$custom = get_post_custom();
echo $custom["main_meta"][0];
break;
case "tabbed_meta":
$custom = get_post_custom();
echo $custom["tabbed_meta"][0];
break;
case "portfolio_cat":
echo get_the_term_list($post->ID, \'portfolio_cat\', \'\', \', \',\'\');
break;
}
}