Hướng dẫn custom colunm cho post type trong admin wordpress
Mời anh chị xem video:
Code mẫu đây bà con
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
//add_filter('manage_{name_post_type}_posts_columns' add_filter('manage_image_gallery_posts_columns', 'aplg_custom_courses_columns'); function aplg_custom_courses_columns( $columns ) { $columns = array( 'image' => 'Image', 'title' => 'Title', 'date' => 'Date' ); // Remove Date Column //unset($columns['date']); // Return new columns return $columns; } //add_action( 'manage_{name_post_type}_posts_custom_column' add_action( 'manage_image_gallery_posts_custom_column', 'aplg_courses_table_content', 10, 2 ); function aplg_courses_table_content( $column_name, $post_id ) { switch( $column_name ) { case 'image' : $post_thumbnail_id = get_post_thumbnail_id($post_id); $src_thumbnail =wp_get_attachment_image_src($post_thumbnail_id ,'thumbnail'); ?> <img src="<?php echo $src_thumbnail[0]; ?>"> <?php break; } } add_action( 'admin_head', 'my_custom_admin_head' ); function my_custom_admin_head(){ ?> <style> .manage-column.column-image { /* max-width: 235px !important; */ width: 16%; } </style> <?php } |
Mọi sự sao chép xin ghi rõ nguồn là fcwordpress.net
Chuyên trang về wordpress: hướng dẫn thiết kế theme, plugin, thủ thuật wordpress