如何将$term->name(slug)作为文件名添加到自定义列单元格中?
$columns = \'<img src="SLUG_NAME.jpg">\';
function custom_column_header( $columns ){
$columns[\'image\'] = \'Image\';
return $columns;
}
add_filter( "manage_edit-genre_columns", \'custom_column_header\', 10);
function custom_column_content( $value, $column_name, $term_id ){
if ($column_name === \'image\') {
$columns = \'<img src="SLUG_NAME.jpg">\';
}
return $columns;
}
add_action( "manage_genre_custom_column", \'custom_column_content\', 10, 3);
最合适的回答,由SO网友:Sally CJ 整理而成
您可以使用get_term_field()
像这样:
if ($column_name === \'image\') {
$slug = get_term_field( \'slug\', $term_id );
$columns = \'<img src="\' . $slug . \'.jpg">\';
}
或
get_term()
:
if ($column_name === \'image\') {
$term = get_term( $term_id );
$columns = \'<img src="\' . $term->slug . \'.jpg">\';
}