对作者的支持不在仪表板的帖子表中显示作者列

时间:2018-01-19 作者:Mizan

\'supports\' => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'excerpt\', \'comments\', \'revisions\', \'custom-fields\' ),`
此参数应在wordpress dashboard的post表中显示author列,但它不在优雅主题的“Explorable”中的“listing”自定义post类型中。

有什么想法吗?

更新:我认为这部分代码限制了post表中的author,如何向其中添加author:

    add_filter( \'manage_edit-listing_columns\', \'et_listing_edit_columns\' );
function et_listing_edit_columns( $columns ) {
    $columns = array(
        \'cb\'                    => \'<input type="checkbox" />\',
        \'title\'                 => __( \'Title\', \'Explorable\' ),
        \'et_listing_type\'       => __( \'Type\', \'Explorable\' ),
        \'et_listing_location\'   => __( \'Location\', \'Explorable\' ),
    );

    return $columns;
}

add_action( \'manage_posts_custom_column\', \'et_listing_custom_columns\' );
function et_listing_custom_columns( $column ) {
    $custom_fields = get_post_custom();

    switch ( $column ) {
        case \'et_listing_type\' :
            $et_listing_types = get_the_terms( get_the_ID(), \'listing_type\' );

            if ( !empty( $et_listing_types ) ) {
                $out = array();
                foreach ( $et_listing_types as $et_listing_type ) {
                    $out[] = sprintf( \'<a href="%s">%s</a>\',
                        esc_url( add_query_arg( array( \'post_type\' => \'listing\', \'listing_type\' => $et_listing_type->slug ), \'edit.php\' ) ),
                        esc_html( sanitize_term_field( \'name\', $et_listing_type->name, $et_listing_type->term_id, \'listing_type\', \'display\' ) )
                    );
                }

                echo join( \', \', $out );
            } else {
                _e( \'None\', \'Explorable\' );
            }

            break;
        case \'et_listing_location\' :

            $et_listing_locations = get_the_terms( get_the_ID(), \'listing_location\' );

            if ( !empty( $et_listing_locations ) ) {
                $out = array();
                foreach ( $et_listing_locations as $et_listing_location ) {
                    $out[] = sprintf( \'<a href="%s">%s</a>\',
                        esc_url( add_query_arg( array( \'post_type\' => \'listing\', \'listing_location\' => $et_listing_location->slug ), \'edit.php\' ) ),
                        esc_html( sanitize_term_field( \'name\', $et_listing_location->name, $et_listing_location->term_id, \'listing_location\', \'display\' ) )
                    );
                }

                echo join( \', \', $out );
            } else {
                _e( \'None\', \'Explorable\' );
            }

            break;
    }
}

1 个回复
SO网友:Shibi

只需添加和删除所需的列,而不是更改所有列。

add_filter( \'manage_edit-listing_columns\', \'et_listing_edit_columns\' );
function et_listing_edit_columns( $columns ) {

    $columns[\'et_listing_type\'] = __( \'Type\', \'Explorable\' );
    $columns[\'et_listing_location\'] = __( \'Location\', \'Explorable\' );

    // You can remove columns with unset()
    return $columns;
}

结束

相关推荐