Created
May 21, 2013 02:48
-
-
Save chrisrouse/5617201 to your computer and use it in GitHub Desktop.
This adds a custom column to show the feature image of a post.
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
<?php | |
/* | |
Plugin Name: Featured Image in Post List | |
Description: This plugin allows you to see the featured image for each post in the Post list. | |
Version: 0.1 | |
License: GPL | |
Author: Chris Rouse | |
Author URI: www.chrisrouse.us | |
*/ | |
/*--------------------------------------------* | |
* Add the featured image to the Post list. | |
*---------------------------------------------*/ | |
/** | |
* Adds the image size for the thumbnails in the Post list. | |
* Currently set to 100x100 pixels. | |
**/ | |
if ( function_exists( 'add_theme_support' ) ) { | |
add_image_size( 'admin-thumb', 100, 100 ); } | |
/*--------------------------------------------* | |
* Adds the new column to the Admin Post View as the first column. | |
*---------------------------------------------*/ | |
add_filter( 'manage_edit-post_columns', 'my_columns_filter', 10, 1 ); | |
function my_columns_filter( $columns ) { | |
$column_thumbnail = array( 'thumbnail' => 'Thumbnail' ); | |
$columns = array_slice( $columns, 0, 1, true ) + $column_thumbnail + array_slice( $columns, 1, NULL, true ); | |
return $columns; | |
} | |
add_action( 'manage_posts_custom_column', 'my_column_action', 10, 1 ); | |
function my_column_action( $column ) { | |
global $post; | |
switch ( $column ) { | |
case 'thumbnail': | |
echo get_the_post_thumbnail( $post->ID, 'admin-thumb' ); | |
break; | |
} | |
} | |
/*--------------------------------------------* | |
* Sets the width of the Thumbnail column. | |
*---------------------------------------------*/ | |
add_action('admin_head', 'my_column_width'); | |
function my_column_width() { | |
echo '<style type="text/css">'; | |
echo '.column-thumbnail { width:110px !important; overflow:hidden }'; | |
echo '</style>'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment