manage_posts_custom_column
最后更新于:2021-11-27 06:06:42
do_action( ‘manage_posts_custom_column’, string $column_name, int $post_id )
Fires in each custom column in 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
function custom_columns( $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)', 'your_text_domain' ); } break; case 'publisher': echo get_post_meta( $post_id, 'publisher', true ); break; } } add_action( 'manage_posts_custom_column' , 'custom_columns', 10, 2 );
/* Display custom column stickiness */ function display_posts_stickiness( $column, $post_id ) { if ($column == 'sticky'){ echo '<input type="checkbox" disabled', ( is_sticky( $post_id ) ? ' checked' : ''), '/>'; } } add_action( 'manage_posts_custom_column' , 'display_posts_stickiness', 10, 2 ); /* Add custom column to post list */ function add_sticky_column( $columns ) { return array_merge( $columns, array( 'sticky' => __( 'Sticky', 'your_text_domain' ) ) ); } add_filter( 'manage_posts_columns' , 'add_sticky_column' );