Skip to content

@corvannoorloos /gist:1989734
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Create 'product' post type thumbnail column
<?php
add_action( 'after_setup_theme', 'cor_after_setup_theme' );
/**
* lorem
*/
function cor_after_setup_theme() {
add_image_size( 'edit-screen-thumbnail', 48, 48, true );
}
add_filter( 'manage_edit-product_columns', 'cor_add_thumbnail_column', 10, 1 );
/**
* Create 'product' post type thumbnail column.
*
* @param unknown_type $column
* @return number
*/
function cor_add_thumbnail_column( $column ) {
$column_thumbnail = array( 'thumbnail' => '' );
$column = array_slice( $column, 0, 1, true ) + $column_thumbnail + array_slice( $column, 1, NULL, true );
return $column;
}
add_action( 'manage_posts_custom_column', 'cor_manage_column_thumbnail', 10, 1 );
/**
* Get the column thumbnail.
*/
function cor_manage_column_thumbnail() {
global $post;
$attachments = get_children( array( 'numberposts' => 1, 'post_mime_type' => 'image', 'post_parent' => $post->ID, 'post_type' => 'attachment' ) );
if ( has_post_thumbnail() ) {
echo get_the_post_thumbnail( $post->ID, 'edit-screen-thumbnail' );
} elseif ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo wp_get_attachment_image( $attachment->ID, 'edit-screen-thumbnail' );
}
} else {
echo '<img src="' . plugins_url( '/img/edit-screen-thumbnail.png', __FILE__ ) . '">';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.