为什么值没有显示在自定义帖子栏中?

时间:2011-06-23 作者:Alexey

我有点麻烦。

/* 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;
    }
}

1 个回复
最合适的回答,由SO网友:Scott 整理而成

add_action( \'manage_post_custom_column\', \'price_column_display\', 10, 2 );

这条线错了。我认为应该是:

add_action( \'manage_catalog_post_custom_column\', \'price_column_display\', 10, 2 );

挂钩格式如下:

manage_{$post_type}_posts_custom_column

EDIT:

请尝试自定义列代码,如以下代码所示。我知道在这种格式下它是有效的:

add_action(\'manage_stores_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 \'town\':
            echo $custom["sc_stores_town"][0];
        break;

        case \'road\':
            echo $custom["sc_stores_road"][0];
        break;
    }
}

结束

相关推荐

在users.php中使用Manage_User_Columns显示cimy用户字段

我正在尝试向我的主题函数添加代码。php在仪表板用户中显示使用Cimy用户额外字段插件创建的字段。php。我知道我需要使用manage\\u users\\u列,但除此之外,我陷入了困境。有谁对这个插件足够熟悉,可以帮助我获得要显示的正确字段?