回答:
質問が約であると仮定しwp_get_attachment_image_srcます。
についても考えられますwp_get_attachment_linkが、関連していますが、この分析には含まれていません。
この問題に答えてこの問題を認識しました:Media ManagerでWPで生成されたすべてのサムネイルを表示するにはどうすればよいですか?。この質問の
問題に関する作業コードを確認するには、それを参照してください。
そして、それはこのWordPressフォーラムのトピックにつながります。
関数wp_get_attachment_image_src($ attachment_id、$ size、$ icon)は、以下を含む配列を返します。
[0] => url  
[1] => width  
[2] => height  
[3] => is intermediate場合は[3]falseで、original画像データが返されます。
どちら wp_get_attachment_image_srcとwp_get_attachment_link機能に依存してimage_downsize、内部/wp-includes/media.php。
そして、この4つの項目の配列が返されます。
これについてはよくわかりませんが、phpのgetimagesize()関数を次のように使用できます。
//This must be in one loop
if(has_post_thumbnail()) {
    $wanted_width = 300;
    $wanted_height = 150;
    $id = get_post_thumbnail_id()
    $image = wp_get_attachment_image_src($id);
    if ($image){
        list($width, $height) = getimagesize($image[0]);
        if (($wanted_height = $width) && ($wanted_height = $height)){
            the_post_thumbnail();
        }
        else{
            //default when no image
            echo '<img src="'.get_bloginfo("template_url").'/images/img-default.png" />';
        }
    }
    else{
        //default when no image
        echo '<img src="'.get_bloginfo("template_url").'/images/img-default.png" />';
    }
} else {
    //default when no image
    echo '<img src="'.get_bloginfo("template_url").'/images/img-default.png" />';
}私はそれが直接質問への答えではないことを知っていますが、AJAXサムネイル再構築と呼ばれる プラグインを使用できます-このプラグインを使用すると、投稿のサムネイルを再構築できます。投稿のサムネイルをすでにアップロードした後でadd_image_size()を使用すると便利です。
これは、要求されたサイズが存在する場合にのみサムネイルを表示する方法でした。
if ( has_post_thumbnail() )  {
    $imgdata = wp_get_attachment_image_src( get_post_thumbnail_id(), 'thumbnail' ); //change thumbnail to whatever size you are using
    $imgwidth = $imgdata[1]; // thumbnail's width                   
    $wanted_width = 300; //change this to your liking
    if ( ($imgwidth < $wanted_width ) ) {
        the_post_thumbnail();
    } else { 
        //do whatever you want
    }
}実際に画像サイズが存在しない場合に自動的に作成するプラグインがあります。http://austinmatzko.com/wordpress-plugins/filosofo-custom-image-sizes/
私はまだこのプラグインを使用する必要はありません。しかし、それは一撃の価値があります。同様の機能をWPコアに追加することについての話があります。おそらく3.2にあるでしょう。http://core.trac.wordpress.org/ticket/15311
それはより良い方法のようです。グローバル変数$ _wp_additional_image_sizesを使用してください。登録されているすべてのimage_sizeが格納されます。したがって、画像サイズ名が定義されているかどうかを確認する場合は、次のようにします。
  global $_wp_additional_image_sizes;
  if ( array_key_exists( 'desired-image-size' , $_wp_additional_image_sizes) )
  {
    //your code here
  }
  else
  {
    //default code here 
  }最善の方法は、Wordpressの組み込み「get_intermediate_image_sizes」関数を使用して、画像サイズの完全なリストを配列として返し、それを確認することです。
show_image_by_size( 10470, 'custom_size' );
function show_image_by_size( $_post_id, $_desired_size ) {
  $_sizes = get_intermediate_image_sizes();
  $_thumbnail_id = get_post_thumbnail_id( $_post_id );
  $_image_size = ( in_array( $_desired_size , $_sizes ) ) ? $_desired_size : 'full';
  $image = wp_get_attachment_image_src( $_thumbnail_id, $_image_size );
  echo '<img src="' . esc_url( $image[0] ) . '" />';
}多分これは助けるでしょう
<?php 
//This must be in a loop
if(has_post_thumbnail()) {
    the_post_thumbnail();
} else {
    echo '<img src="'.get_bloginfo("template_url").'/images/img-default.png" />';
}
?>から:http : //codex.wordpress.org/Function_Reference/has_post_thumbnail
 
このようなものを使用して、画像サイズが存在するかどうかを確認します。
if (function_exists('has_post_thumbnail') && has_post_thumbnail('medium')) {
//// code to display thumbnail goes here
}
else {
/// otherwise do this
}それがあなたを動かすのに役立つことを願っています。