我有点麻烦。
/* Catalog */
function my_post_type_catalog() {
register_post_type( \'catalog\',
array(
\'label\' => __(\'Catalog\'),
\'public\' => true,
\'show_ui\' => true,
\'show_in_nav_menus\' => true,
\'rewrite\' => true,
\'hierarchical\' => true,
\'menu_position\' => 5,
\'supports\' => array(
\'title\',
\'editor\',
\'thumbnail\',
\'excerpt\')
)
);
register_taxonomy(\'catalog_cat\', \'catalog\', array(\'hierarchical\' => true, \'label\' => \'Catalog category\', \'singular_name\' => \'catalog_category\'));
}
add_action(\'init\', \'my_post_type_catalog\');
add_action("admin_init", "admin_init");
function admin_init(){
add_meta_box("catalogdetails_meta", "Price:", "catalog_meta", "catalog", "normal", "low");
}
function catalog_meta() {
global $post;
$custom = get_post_custom($post->ID);
$price = $custom["price"][0];
?>
<div id=\'peoplemanager_form_container\'>
<div id=\'shortanswers\'>
<p><input name="price" size="35" value="<?php echo $price; ?>"></p>
</div>
</div>
<?php
}
add_action(\'save_post\', \'save_details\');
function save_details(){
global $post;
update_post_meta($post->ID, "price", $_POST["price"]);
}
// Register the column
function price_column_register( $columns ) {
$columns[\'price\'] = __( \'Price\' );
return $columns;
}
add_filter( \'manage_edit-catalog_columns\', \'price_column_register\' );
// Display the column content
function price_column_display( $column_name, $post_id ) {
if ( \'price\' != $column_name )
return;
$price = get_post_meta($post_id, \'price\', true);
if ( !$price )
$price = \'<em>\' . __( \'undefined\' ) . \'</em>\';
echo $price;
}
add_action( \'manage_catalog_post_custom_column\', \'price_column_display\', 10, 2 );
// Register the column as sortable
function price_column_register_sortable( $columns ) {
$columns[\'price\'] = \'price\';
return $columns;
}
add_filter( \'manage_edit-catalog_sortable_columns\', \'price_column_register_sortable\' );
function price_column_orderby( $vars ) {
if ( isset( $vars[\'orderby\'] ) && \'price\' == $vars[\'orderby\'] ) {
$vars = array_merge( $vars, array(
\'meta_key\' => \'price\',
\'orderby\' => \'meta_value_num\'
) );
}
return $vars;
}
add_filter( \'request\', \'price_column_orderby\' );
价格值未显示。我做错了什么
。。。感谢
@Brady需要替换此代码:
// Display the column content
function price_column_display( $column_name, $post_id ) {
if ( \'price\' != $column_name )
return;
$price = get_post_meta($post_id, \'price\', true);
if ( !$price )
$price = \'<em>\' . __( \'undefined\' ) . \'</em>\';
echo $price;
}
add_action( \'manage_catalog_post_custom_column\', \'price_column_display\', 10, 2 );
收件人:
// Display the column content
add_action(\'manage_catalog_posts_custom_column\', \'sc_stores_manage_columns\', 10, 2);
function sc_stores_manage_columns($column_name, $id) {
$custom = get_post_custom($id);
switch ($column_name) {
case \'price\':
if ($custom["price"][0]==""){echo "none";}
echo $custom["price"][0];
break;
}
}