0

I am just about finished creating custom columns through the WordPress admin panel.

The custom post type I am using is called "slides". I figured out how to add the column titles and all of the column content (because they're WordPress defaults)...what I am missing is how do I add content to the "thumbnail" column? Some kind of if statement like: if admin-thumbnail exists display the admin-thumbnail image...which sounds simple enough, I just don't know how to add it to that specific column.

The code I have so far is: http://pastebin.com/YfuYUW5c.

Thanks, Josh

1

first create the new column:

add_filter( 'manage_edit-post_columns', 'c3m_new_column');
function c3m_new_column( $defaults ) {
    $dfaults['post_thumbnail'] = 'Post Thumbnail';
    return $defaults;
}

Now the function to output the thumbnails in the column:

add_action( 'manage_posts_custom_column', 'c3m_custom_column', 10, 2);
function c3m_custom_column( $column_name, $post_id ) {
    if ($column_name == 'post_thumbnail') {
        if ( has_post_thumbnail() ) {
            $img_url = wp_get_attachment_image_src( get_post_thumbnail_id() );
            echo '<img src="'. esc_url( $img_url[0] ).'" />';
        } else { echo 'No Post Thumbnail Set'; }
    }
  • Do you need the global $post; in c3m_custom_column? – westondeboer Jul 3 '12 at 4:11
  • no, you do not need , also, you can simply use the_post_thumbnail( array(100,100) ) //or other size .. instead of $img_URL array .. – krembo99 Jul 3 '12 at 4:14
1

Chris,

I modified the following (and the code is working!): http://pastebin.com/HZWgHrZf.

I got it here: http://justintadlock.com/archives/2011/06/27/custom-columns-for-custom-post-types

For every column you simply add another case :)

Thanks, Josh

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.