Created
March 20, 2017 17:21
-
-
Save artikus11/307ec668e51c0cc397a5c2ffec452791 to your computer and use it in GitHub Desktop.
Колонки с миниатюрами в админке
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Get Featured image | |
add_filter( 'manage_posts_columns', 'mts_columns_head' ); | |
add_action( 'manage_posts_custom_column', 'mts_columns_content', 10, 2 ); | |
function mts_get_featured_image( $post_ID ) { | |
$post_thumbnail_id = get_post_thumbnail_id( $post_ID ); | |
if ( $post_thumbnail_id ) { | |
$post_thumbnail_img = wp_get_attachment_image_src( $post_thumbnail_id, 'thumbnail' ); | |
return $post_thumbnail_img[0]; | |
} | |
} | |
function mts_columns_head( $defaults ) { | |
$defaults['featured_image'] = 'Миниатюра'; | |
return $defaults; | |
} | |
function mts_columns_content( $column_name, $post_ID ) { | |
if ( $column_name == 'featured_image' ) { | |
$post_featured_image = mts_get_featured_image( $post_ID ); | |
if ( $post_featured_image ) { | |
echo '<img width="100" src="' . $post_featured_image . '" />'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment