分类未显示在仪表板上的列中

时间:2013-08-09 作者:Dave Burns

我在试图将分类法显示在仪表板的post列中时遇到了一些问题,自定义函数显示正确,只是分类法不正确,有人知道我哪里出了问题吗?以下是显示问题的屏幕截图:http://i.imgur.com/GiMSfhF.png

// Add filters for the Games Database in the control panel
add_filter( \'manage_edit-games_database_columns\', \'my_columns\' );
function my_columns( $columns ) {
$columns[\'games_database_platform\'] = \'Platform\'; // Taxonomy
$columns[\'games_database_genre\'] = \'Genre\'; // Taxonomy
$columns[\'games_database_publisher\'] = \'Publisher\'; // Custom Function
$columns[\'games_database_developer\'] = \'Developer\'; // Custom Function
$columns[\'games_database_rating\'] = \'Review Score\'; // Custom Function
unset( $columns[\'comments\'] );
return $columns;
}
add_action( \'manage_posts_custom_column\', \'populate_columns\' );
function populate_columns( $column ) {
if ( \'games_database_publisher\' == $column ) {
    $game_publisher = esc_html( get_post_meta( get_the_ID(), \'game_publisher\', true )     );
    echo $game_publisher;
}
elseif ( \'games_database_developer\' == $column ) {
    $game_developer = get_post_meta( get_the_ID(), \'game_developer\', true );
    echo $game_developer;
}
elseif ( \'games_database_rating\' == $column ) {
    $game_rating = get_post_meta( get_the_ID(), \'game_rating\', true );
    echo $game_rating . \'%\';
}
elseif ( \'games_database_platform\' == $column ) {
    $game_platform = get_post_meta( get_the_ID(), \'games_database_game_platform\', true );
    echo $game_platform;
}
elseif ( \'games_database_rating\' == $column ) {
    $game_rating = get_post_meta( get_the_ID(), \'game_rating\', true );
    echo $game_rating . \'%\';
}
}

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

呼叫register_taxonomy() 具有\'show_admin_column\' => TRUE WordPress将自动创建您的列。此参数为added in version 3.5. 您不再需要自定义筛选器。

我编写了一个小插件来演示这种情况:t5-taxonomy-location.

这是注册码:

protected function register_taxonomy()
{
    $this->set_labels();

    $args = array (
        \'labels\'            => $this->labels,
        \'label\'             => $this->labels[\'singular_name\'],
        \'public\'            => TRUE,
        \'show_in_nav_menus\' => TRUE,
        \'show_ui\'           => TRUE,
        \'show_tagcloud\'     => TRUE,
        \'rewrite\'           => array (
            \'slug\'       => _x( \'location\', \'slug\', \'plugin_t5_tax_location\' ),
            \'with_front\' => apply_filters( \'t5_tax_location_slug_front\', FALSE )
        ),
        \'query_var\'         => \'location\',
        \'hierarchical\'      => TRUE,
        // New in WordPress 3.5
        // see http://core.trac.wordpress.org/ticket/21240
        \'show_admin_column\' => TRUE
    );

    $tax_post_types = apply_filters(
        \'t5_tax_location_post_types\',
        array( \'post\', \'page\', \'attachment\' )
    );

    register_taxonomy( $this->taxonomy, $tax_post_types, $args );
}

结束

相关推荐

wordpress taxonomy results

我正在使用分类法。php从数据库中获取一些行。在分类法页面上,函数get\\u queryed\\u object()显示我从数据库中得到了正确的结果,但wordpress循环if ( have_posts() ) : while ( have_posts() ) : the_post(); 正在循环数据库中的所有行。have\\u posts()是否总是迭代数据库中的所有行?编辑:query_posts(\"post_type=taxonomy_name&posts_per_page=6\");