WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Feature Image column in WP Admin for custom posts (2 posts)

  1. iyamdman
    Member
    Posted 2 years ago #

    I have added code to my function.php file to add the Featured Image of a post to my admin column. It works great for posts and pages, but for my two custom post types (cars, wheels) it dosen't do anything to the admin layout.

    Can someone help me with this?

    Do I need to add a filter for each custom post?

    I got this code from here:

    http://www.tcbarrett.com/2011/10/add-featured-image-thumbnail-to-wordpress-admin-columns/

    The following code in my function.php file:

    // Add the posts and pages columns filter. They can both use the same function.
    	add_filter('manage_posts_columns', 'tcb_add_post_thumbnail_column', 5);
    	add_filter('manage_pages_columns', 'tcb_add_post_thumbnail_column', 5);
            add_filter('manage_custom_post_columns', 'tcb_add_post_thumbnail_column', 5);
    
    	// Add the column
    	function tcb_add_post_thumbnail_column($cols){
    	  $cols['tcb_post_thumb'] = __('FeaTured');
    	  return $cols;
    	}
    
    	// Hook into the posts an pages column managing. Sharing function callback again.
    	add_action('manage_posts_custom_column', 'tcb_display_post_thumbnail_column', 5, 2);
    	add_action('manage_pages_custom_column', 'tcb_display_post_thumbnail_column', 5, 2);
            add_action('manage_custom_post_column', 'tcb_display_post_thumbnail_column', 5, 2);
    
    	// Grab featured-thumbnail size post thumbnail and display it.
    	function tcb_display_post_thumbnail_column($col, $id){
    	  switch($col){
    	    case 'tcb_post_thumb':
    	      if( function_exists('the_post_thumbnail') )
    	        echo the_post_thumbnail( 'admin-list-thumb' );
    	      else
    	        echo 'Not supported in theme';
    	      break;
    	  }
    	}
  2. Sebastian Cork
    Member
    Posted 2 years ago #

    Hi,

    You may be interested in trying out Admin Thumbnails, as it accomplishes what you are trying to do.

    I have tested it with the latest stable release of WordPress and found that it works fine.

Topic Closed

This topic has been closed to new replies.

About this Topic