星期三 , 22 1 月 2025

product文章类型添加缩略图到管理列

add_filter( 'manage_product_posts_columns', 'br_product_custom_column' );


function br_product_custom_column($columns) {

	$columns['thumbnail']  =  __('Thumbnail');

	return $columns;

}

add_action( 'manage_product_posts_custom_column', 'br_add_thumbnail_column',10,2 );


function br_add_thumbnail_column($column_name,$post_id) {

	if ($column_name == 'thumbnail') {

		$thumbnail = get_the_post_thumbnail( $post_id,array(50,50) );

		echo $thumbnail ? $thumbnail : 'N/A';
		
	}


}
//如果要重组 列  

function my_product_columns($defaults) {
  $my_order = array(
    'cb' => $defaults['cb'],  // Checkbox
    'thumbnail' => __('Thumbnail', 'your-text-domain'), // Thumbnail column
    'title' => $defaults['title'],
    'comments' => $defaults['comments'],
    'date' => $defaults['date'],
  );
  return $my_order;
}
add_filter('manage_product_posts_columns', 'my_product_columns');