在缺少后期元的情况下替换图像的函数

时间:2020-08-10 作者:Vincenzo Piromalli

我在函数中有thtis函数。php文件

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.org/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);
如果$poster\\u路径为空(或此字段没有post meta),我需要一些lik echo

1 个回复
SO网友:Vincenzo Piromalli

找到解决方案:

    $poster_path = get_post_meta($post->ID, "poster_path", $single = true);           
    if( $poster_path == "" ){ 
    echo \'<img width="53" height="80" src="https://via.placeholder.com/370x556?text=No+Poster&000.jpg" />\'; 
    } else {
    echo \'<img width="53" height="80" src="https://image.tmdb.org/t/p/w370_and_h556_bestv2\'.$poster_path.\'" />\';
    }

相关推荐

Variables posting twice

我希望创建一个新变量,如codex中所述,但在提交URL时,变量会两次提交给我的函数我已经在一个插件中尝试了这一点function.php. 我还尝试使用wp_reset_query() 以下是我的示例代码:add_filter(\'query_vars\', \'my_function\'); function my_function ($vars) { $vars[] = \'Q1\'; $vars[] = \'Q2\'; return $v