admin管理员组文章数量:1326524
i have thtis function in functions.php file
function post_manage_columns($column_name, $id) {
global $post;
switch ($column_name) {
case 'Average':
echo get_post_meta( $post->ID , 'imdbRating' , true );
break;
case 'Runtime':
echo get_post_meta( $post->ID , 'Runtime' , true );
break;
case 'Poster':
$poster_path = ";.get_post_meta($post->ID, "poster_path", $single = true);
echo '<img width="53" height="80" src="'.$poster_path.'" />';
break;
case 'years':
$terms = get_the_term_list( $post_id, 'years', '', ',', '' );
if ( is_string( $terms ) ) {
echo $terms;
} else {
_e( 'Unable to get year', 'movietv' );
}
break;
}
}
add_action('manage_post_posts_custom_column', 'post_manage_columns', 10, 2);
i need some lik if $poster_path is empty (or there is no post meta for this field) echo
i have thtis function in functions.php file
function post_manage_columns($column_name, $id) {
global $post;
switch ($column_name) {
case 'Average':
echo get_post_meta( $post->ID , 'imdbRating' , true );
break;
case 'Runtime':
echo get_post_meta( $post->ID , 'Runtime' , true );
break;
case 'Poster':
$poster_path = "https://image.tmdb/t/p/w370_and_h556_bestv2".get_post_meta($post->ID, "poster_path", $single = true);
echo '<img width="53" height="80" src="'.$poster_path.'" />';
break;
case 'years':
$terms = get_the_term_list( $post_id, 'years', '', ',', '' );
if ( is_string( $terms ) ) {
echo $terms;
} else {
_e( 'Unable to get year', 'movietv' );
}
break;
}
}
add_action('manage_post_posts_custom_column', 'post_manage_columns', 10, 2);
i need some lik if $poster_path is empty (or there is no post meta for this field) echo
Share Improve this question asked Aug 10, 2020 at 15:06 Vincenzo PiromalliVincenzo Piromalli 1989 bronze badges 2- 1 Can you post the answer as an answer instead of a comment? – Tom J Nowell ♦ Commented Aug 10, 2020 at 16:27
- Ok, thanks, i'm newbie :) – Vincenzo Piromalli Commented Aug 10, 2020 at 16:43
1 Answer
Reset to default 1found the solution:
$poster_path = get_post_meta($post->ID, "poster_path", $single = true);
if( $poster_path == "" ){
echo '<img width="53" height="80" src="https://via.placeholder/370x556?text=No+Poster&000.jpg" />';
} else {
echo '<img width="53" height="80" src="https://image.tmdb/t/p/w370_and_h556_bestv2'.$poster_path.'" />';
}
本文标签: custom fieldFunction that replaces the image in the absence of the post meta
版权声明:本文标题:custom field - Function that replaces the image in the absence of the post meta 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742199019a2431610.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论