Add category custom admin column

Published
2023-01-09
浏览次数 :  11

### 使用tax_meta_class 时候将分类图片显示到管理栏 
add_filter( 'manage_edit-category_columns', 'add_cat_cover_column' );

function add_cat_cover_column($columns)
{
  $columns['cover'] = esc_html__('COVER','hablog');
  return $columns;
}

add_action( 'manage_category_custom_column', 'cat_cover_custom_column_content',10,3 );
//add_filter('manage_category_custom_column','cat_cover_custom_column_content',1,2);
function cat_cover_custom_column_content($string,$columns,$term_id) {

  if (!empty(get_term_meta( $term_id, 'ha_image_field_id', true ))) {
    $cat_cover = get_term_meta( $term_id, 'ha_image_field_id', true );
  } else {
    $cat_cover = '';
  }
  switch ($columns) {

    case 'cover':
      // code...
      if (!empty($cat_cover)) {
        echo '<img width=50 height=50 src='.$cat_cover['url'].'>';
      } else {
        echo 'No cover found!';
      }

      break;
  }
}

  • 标签1
  • 标签1
  • 标签1
Top