最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

custom field - Function that replaces the image in the absence of the post meta

programmeradmin0浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 1

found 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.'" />';
    }
发布评论

评论列表(0)

  1. 暂无评论