manage_pages_custom_column
最后更新于:2021-11-27 06:00:29
do_action( ‘manage_pages_custom_column’, string $column_name, int $post_id )
Fires in each custom column on the Posts list table.
参数
- $column_name
-
(string)
The name of the column to display. - $post_id
-
(int)
The current post ID.
源文件
文件: gc-admin/includes/class-gc-posts-list-table.php
add_filter( 'manage_pages_columns', 'page_column_views' ); add_action( 'manage_pages_custom_column', 'page_custom_column_views', 5, 2 ); function page_column_views( $defaults ) { $defaults['page-layout'] = __('Template', 'textdomain'); return $defaults; } function page_custom_column_views( $column_name, $id ) { if ( $column_name === 'page-layout' ) { $set_template = get_post_meta( get_the_ID(), '_gc_page_template', true ); if ( $set_template == 'default' ) { echo __('Default Template', 'textdomain'); } $templates = get_page_templates(); ksort( $templates ); foreach ( array_keys( $templates ) as $template ) : if ( $set_template == $templates[$template] ) echo $template; endforeach; } }
// Add the custom columns to the book post type: add_filter( 'manage_book_posts_columns', 'set_custom_edit_book_columns' ); function set_custom_edit_book_columns($columns) { unset( $columns['author'] ); $columns['book_author'] = __( 'Author', 'textdomain' ); $columns['publisher'] = __( 'Publisher', 'textdomain' ); return $columns; } // Add the data to the custom columns for the book post type: add_action( 'manage_book_posts_custom_column' , 'custom_book_column', 10, 2 ); function custom_book_column( $column, $post_id ) { switch ( $column ) { case 'book_author' : $terms = get_the_term_list( $post_id , 'book_author' , '' , ',' , '' ); if ( is_string( $terms ) ) echo $terms; else _e( 'Unable to get author(s)', 'textdomain' ); break; case 'publisher' : echo get_post_meta( $post_id , 'publisher' , true ); break; } }