Title: 同じサムネイル画像が重複して表示されてしまう
Last modified: 2011年3月9日

---

# 同じサムネイル画像が重複して表示されてしまう

 *  解決済 [モグラ](https://ja.wordpress.org/support/users/tenpra/)
 * (@tenpra)
 * [15年、 8ヶ月前](https://ja.wordpress.org/support/topic/%e5%90%8c%e3%81%98%e3%82%b5%e3%83%a0%e3%83%8d%e3%82%a4%e3%83%ab%e7%94%bb%e5%83%8f%e3%81%8c%e9%87%8d%e8%a4%87%e3%81%97%e3%81%a6%e8%a1%a8%e7%a4%ba%e3%81%95%e3%82%8c%e3%81%a6%e3%81%97%e3%81%be%e3%81%86/)
 * トップページに記事のサムネイル画像と、本文を抽出して表示させていまして、
    本文
   は65文字以内、画像は上限4枚まで表示という様にしているのですが、 何故か記事中に
   は1つしか画像を投稿していないのに、 サムネイルの同じ画像が数枚重複して表示され
   てしまうのです。
 * 下記サイトの中段お知らせ部分の一番上の記事です。
    [http://www.ebisuya.com/test110221](http://www.ebisuya.com/test110221)
 * 下記が埋め込んでいるタグです。
 *     ```
       <div id="news">
       <h2>お知らせ</h2>
       <p class="list"><a href="info_test/">お知らせ一覧</a></p>
       <?php query_posts('cat=3&showposts=3'); ?>
       <?php while (have_posts()) : the_post(); ?>
                           <h3><?php echo date("Y年m月d日", strtotime($post->post_date)); ?><br>
       <strong><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></strong></h3>
       <p><?php echo mb_substr(strip_tags($post-> post_content), 0, 65); ?>...<p>
   
       <p><a href="<?php the_permalink() ?>" class="thum-mini">
       <?php
       $images = get_children( array(
       'post_parent' => get_the_ID(),
       'post_type' => 'attachment',
       'post_mime_type' => 'image',
       'orderby' => 'menu_order',
       'order' => 'ASC',
       ) );
       $i=0;
       foreach ( (array) $images as $attachment_id => $attachment ) {
        $src = wp_get_attachment_image_src( $attachment_id, 'thumbnail' );
         echo '<img width="150"  src="' . $src[0] . '" />';
       if (2<$i){
       break;
       }
       $i++;
       }
       ?></a></p>
       <p class="details"><a href="<?php the_permalink(); ?>">詳細を見る</a></p>
         <?php endwhile;?>
       </div>
       ```
   
 * 原因が分かりません。。
    どなたか解決方法をご教授頂けると助かります＞＜

12件の返信を表示中 - 1 - 12件目 (全12件中)

 *  [V.J.Catkick](https://ja.wordpress.org/support/users/vjcatkick-1/)
 * (@vjcatkick-1)
 * [15年、 8ヶ月前](https://ja.wordpress.org/support/topic/%e5%90%8c%e3%81%98%e3%82%b5%e3%83%a0%e3%83%8d%e3%82%a4%e3%83%ab%e7%94%bb%e5%83%8f%e3%81%8c%e9%87%8d%e8%a4%87%e3%81%97%e3%81%a6%e8%a1%a8%e7%a4%ba%e3%81%95%e3%82%8c%e3%81%a6%e3%81%97%e3%81%be%e3%81%86/#post-137179)
 * `$i=0;`
 * `if (2<$i){ break; } $i++;`
 * これだと絵が１枚しか存在しなくても必ず２回ループしますよね…。１枚の時にどうした
   いかの条件判断が抜けてます。
 *  トピック投稿者 [モグラ](https://ja.wordpress.org/support/users/tenpra/)
 * (@tenpra)
 * [15年、 8ヶ月前](https://ja.wordpress.org/support/topic/%e5%90%8c%e3%81%98%e3%82%b5%e3%83%a0%e3%83%8d%e3%82%a4%e3%83%ab%e7%94%bb%e5%83%8f%e3%81%8c%e9%87%8d%e8%a4%87%e3%81%97%e3%81%a6%e8%a1%a8%e7%a4%ba%e3%81%95%e3%82%8c%e3%81%a6%e3%81%97%e3%81%be%e3%81%86/#post-137180)
 * V.J.Catkickさん
 * お返事有難う御座います。
 * 試に、下記の様にソースを書きかえたのですが、
    やはり同じ画像が表示されてしまい
   ます。
 *     ```
       <div id="news">
       			<h2>お知らせ</h2>
       			<p class="list"><a href="info_test/">お知らせ一覧</a></p>
       <?php query_posts('cat=3&showposts=3'); ?>
       <?php while (have_posts()) : the_post(); ?>
                           <h3><?php echo date("Y年m月d日", strtotime($post->post_date)); ?><br>
       <strong><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></strong></h3>
       <p><?php echo mb_substr(strip_tags($post-> post_content), 0, 60); ?>...<p>
   
       <p><a href="<?php the_permalink() ?>" class="thum-mini">
       <?php
       $images = get_children( array(
       'post_parent' => get_the_ID(),
       'post_type' => 'attachment',
       'post_mime_type' => 'image',
       'orderby' => 'menu_order',
       'order' => 'ASC',
       ) );
   
       foreach ( (array) $images as $attachment_id => $attachment ) {
        $src = wp_get_attachment_image_src( $attachment_id, 'thumbnail' );
         echo '<img width="150"  src="' . $src[0] . '" />';
   
       }
   
       ?></a></p>
   
       <p class="details"><a href="<?php the_permalink(); ?>">詳細を見る</a></p>
         <?php endwhile;?>
       ```
   
 * 何か別の原因なのでしょうか？？
 *  [V.J.Catkick](https://ja.wordpress.org/support/users/vjcatkick-1/)
 * (@vjcatkick-1)
 * [15年、 8ヶ月前](https://ja.wordpress.org/support/topic/%e5%90%8c%e3%81%98%e3%82%b5%e3%83%a0%e3%83%8d%e3%82%a4%e3%83%ab%e7%94%bb%e5%83%8f%e3%81%8c%e9%87%8d%e8%a4%87%e3%81%97%e3%81%a6%e8%a1%a8%e7%a4%ba%e3%81%95%e3%82%8c%e3%81%a6%e3%81%97%e3%81%be%e3%81%86/#post-137181)
 * あと気になるのは、get_children()がなにを返しているかというところですね。get_children()
   とforeachの間に
 *     ```
       echo '<!--';
       print_r( $images );
       echo '-->';
       ```
   
 * とか入れて、配列がちゃんと期待通りに吐き出されているかどうか確認してみるといい
   でしょう。
 *  トピック投稿者 [モグラ](https://ja.wordpress.org/support/users/tenpra/)
 * (@tenpra)
 * [15年、 8ヶ月前](https://ja.wordpress.org/support/topic/%e5%90%8c%e3%81%98%e3%82%b5%e3%83%a0%e3%83%8d%e3%82%a4%e3%83%ab%e7%94%bb%e5%83%8f%e3%81%8c%e9%87%8d%e8%a4%87%e3%81%97%e3%81%a6%e8%a1%a8%e7%a4%ba%e3%81%95%e3%82%8c%e3%81%a6%e3%81%97%e3%81%be%e3%81%86/#post-137183)
 * V.J.Catkickさん
 * 度々お返事有難う御座います。
 * [http://www.ebisuya.com/test110221](http://www.ebisuya.com/test110221)
 * 上記のタグを入れ込んでみた所、
 *     ```
       <!--Array
       (
           [4218] => stdClass Object
               (
                   [ID] => 4218
                   [post_author] => 1
                   [post_date] => 2011-03-08 17:48:00
                   [post_date_gmt] => 2011-03-08 08:48:00
                   [post_content] =>
                   [post_title] => bench
                   [post_excerpt] =>
                   [post_status] => inherit
                   [comment_status] => closed
                   [ping_status] => open
                   [post_password] =>
                   [post_name] => bench
                   [to_ping] =>
                   [pinged] =>
                   [post_modified] => 2011-03-08 17:48:00
                   [post_modified_gmt] => 2011-03-08 08:48:00
                   [post_content_filtered] =>
                   [post_parent] => 4216
                   [guid] => http://www.ebisuya.com/wordpress/wp-content/uploads/2011/03/bench.jpg
                   [menu_order] => 0
                   [post_type] => attachment
                   [post_mime_type] => image/jpeg
                   [comment_count] => 0
                   [filter] => raw
               )
   
           [4222] => stdClass Object
               (
                   [ID] => 4222
                   [post_author] => 1
                   [post_date] => 2011-03-08 17:52:32
                   [post_date_gmt] => 2011-03-08 08:52:32
                   [post_content] =>
                   [post_title] => bench
                   [post_excerpt] =>
                   [post_status] => inherit
                   [comment_status] => closed
                   [ping_status] => open
                   [post_password] =>
                   [post_name] => bench-2
                   [to_ping] =>
                   [pinged] =>
                   [post_modified] => 2011-03-08 17:52:32
                   [post_modified_gmt] => 2011-03-08 08:52:32
                   [post_content_filtered] =>
                   [post_parent] => 4216
                   [guid] => http://www.ebisuya.com/wordpress/wp-content/uploads/2011/03/bench1.jpg
                   [menu_order] => 0
                   [post_type] => attachment
                   [post_mime_type] => image/jpeg
                   [comment_count] => 0
                   [filter] => raw
               )
   
           [4224] => stdClass Object
               (
                   [ID] => 4224
                   [post_author] => 1
                   [post_date] => 2011-03-08 17:53:54
                   [post_date_gmt] => 2011-03-08 08:53:54
                   [post_content] =>
                   [post_title] => bench
                   [post_excerpt] =>
                   [post_status] => inherit
                   [comment_status] => closed
                   [ping_status] => open
                   [post_password] =>
                   [post_name] => bench-3
                   [to_ping] =>
                   [pinged] =>
                   [post_modified] => 2011-03-08 17:53:54
                   [post_modified_gmt] => 2011-03-08 08:53:54
                   [post_content_filtered] =>
                   [post_parent] => 4216
                   [guid] => http://www.ebisuya.com/wordpress/wp-content/uploads/2011/03/bench2.jpg
                   [menu_order] => 0
                   [post_type] => attachment
                   [post_mime_type] => image/jpeg
                   [comment_count] => 0
                   [filter] => raw
               )
   
       )
       -->
       ```
   
 * 何故か3つIDを取得しているようです。。。
    ますます謎です。。
 *  [tmatsuur](https://ja.wordpress.org/support/users/tmatsuur/)
 * (@tmatsuur)
 * [15年、 8ヶ月前](https://ja.wordpress.org/support/topic/%e5%90%8c%e3%81%98%e3%82%b5%e3%83%a0%e3%83%8d%e3%82%a4%e3%83%ab%e7%94%bb%e5%83%8f%e3%81%8c%e9%87%8d%e8%a4%87%e3%81%97%e3%81%a6%e8%a1%a8%e7%a4%ba%e3%81%95%e3%82%8c%e3%81%a6%e3%81%97%e3%81%be%e3%81%86/#post-137184)
 * 履歴のようですね。
 * get_childrenのパラメータで
    `'post_status'=> 'publish',` を追加してあげればいい
   と思います。
 *  トピック投稿者 [モグラ](https://ja.wordpress.org/support/users/tenpra/)
 * (@tenpra)
 * [15年、 8ヶ月前](https://ja.wordpress.org/support/topic/%e5%90%8c%e3%81%98%e3%82%b5%e3%83%a0%e3%83%8d%e3%82%a4%e3%83%ab%e7%94%bb%e5%83%8f%e3%81%8c%e9%87%8d%e8%a4%87%e3%81%97%e3%81%a6%e8%a1%a8%e7%a4%ba%e3%81%95%e3%82%8c%e3%81%a6%e3%81%97%e3%81%be%e3%81%86/#post-137189)
 * V.J.Catkickさん
 * お返事有難う御座います。
 * 下記のようにのタグを入れ込んでみた所、
 *     ```
       <?php
       $images = get_children( array(
       'post_parent' => get_the_ID(),
       'post_type' => 'attachment',
       'post_mime_type' => 'image',
       'orderby' => 'menu_order',
       'order' => 'ASC',
       'post_status'=> 'publish',
       ) );
       echo '<!--';
       print_r( $images );
       echo '-->';
       ```
   
 * 画像が出てこなくなってしまいました＞＜
 *  [tmatsuur](https://ja.wordpress.org/support/users/tmatsuur/)
 * (@tmatsuur)
 * [15年、 8ヶ月前](https://ja.wordpress.org/support/topic/%e5%90%8c%e3%81%98%e3%82%b5%e3%83%a0%e3%83%8d%e3%82%a4%e3%83%ab%e7%94%bb%e5%83%8f%e3%81%8c%e9%87%8d%e8%a4%87%e3%81%97%e3%81%a6%e8%a1%a8%e7%a4%ba%e3%81%95%e3%82%8c%e3%81%a6%e3%81%97%e3%81%be%e3%81%86/#post-137190)
 * Tenpraさん、すみません。
    正しいstatusは’inherit’なので、追加はいらなかったみたい
   です。
 * 前の投稿のprint_rの出力を見直してみたのですが、同じ投稿に同じ画像を
    複数アップ
   ロードしているだけかもしれません。 ダッシュボードの「投稿」のすぐ下にある「メディア」
   をプルダウンして 「ライブラリ」をクリック。そこで同じ投稿に画像がリンクされてい
   ないか 確認してみてはいかがでしょうか。
 * あと、ここの場所はこういった質問の投稿場所ではないので、管理人さんに
    移動して
   もらったほうがいいと思います。
 *  モデレーター [JOTAKI, Taisuke](https://ja.wordpress.org/support/users/tai/)
 * (@tai)
 * [15年、 8ヶ月前](https://ja.wordpress.org/support/topic/%e5%90%8c%e3%81%98%e3%82%b5%e3%83%a0%e3%83%8d%e3%82%a4%e3%83%ab%e7%94%bb%e5%83%8f%e3%81%8c%e9%87%8d%e8%a4%87%e3%81%97%e3%81%a6%e8%a1%a8%e7%a4%ba%e3%81%95%e3%82%8c%e3%81%a6%e3%81%97%e3%81%be%e3%81%86/#post-137192)
 * tmatsuurさん、ありがとうございます。
 * Tenpraさん、「テーマ」に移動しました。
 *  トピック投稿者 [モグラ](https://ja.wordpress.org/support/users/tenpra/)
 * (@tenpra)
 * [15年、 8ヶ月前](https://ja.wordpress.org/support/topic/%e5%90%8c%e3%81%98%e3%82%b5%e3%83%a0%e3%83%8d%e3%82%a4%e3%83%ab%e7%94%bb%e5%83%8f%e3%81%8c%e9%87%8d%e8%a4%87%e3%81%97%e3%81%a6%e8%a1%a8%e7%a4%ba%e3%81%95%e3%82%8c%e3%81%a6%e3%81%97%e3%81%be%e3%81%86/#post-137193)
 * 管理人さん、移動ありがとうございます。
    お手数おかけしました。
 * tmatsuurさん
 * お返事ありがとうございます。
    すみません、先ほどお名前間違えてました。。 tmatsuur
   さんのご指摘通り「ライブラリ」に同じ画像が3つ画像がアップされていました。 原因
   がわかったので非常に助かりました＞＜ そうなると、記事中に貼り付けられている画像
   だけを呼び出すようするには、 どのような記述で引っ張り出せば良いでしょう？？ご
   教授頂けると助かります＞＜；
 *  [V.J.Catkick](https://ja.wordpress.org/support/users/vjcatkick-1/)
 * (@vjcatkick-1)
 * [15年、 8ヶ月前](https://ja.wordpress.org/support/topic/%e5%90%8c%e3%81%98%e3%82%b5%e3%83%a0%e3%83%8d%e3%82%a4%e3%83%ab%e7%94%bb%e5%83%8f%e3%81%8c%e9%87%8d%e8%a4%87%e3%81%97%e3%81%a6%e8%a1%a8%e7%a4%ba%e3%81%95%e3%82%8c%e3%81%a6%e3%81%97%e3%81%be%e3%81%86/#post-137201)
 * １つだけにしたいのであれば、foreach文の中で最初の読み込みが終わった（正しく読み
   込まれたという条件判断後）段階でbreak;すればいいんじゃないかな、と思います。
 *  トピック投稿者 [モグラ](https://ja.wordpress.org/support/users/tenpra/)
 * (@tenpra)
 * [15年、 8ヶ月前](https://ja.wordpress.org/support/topic/%e5%90%8c%e3%81%98%e3%82%b5%e3%83%a0%e3%83%8d%e3%82%a4%e3%83%ab%e7%94%bb%e5%83%8f%e3%81%8c%e9%87%8d%e8%a4%87%e3%81%97%e3%81%a6%e8%a1%a8%e7%a4%ba%e3%81%95%e3%82%8c%e3%81%a6%e3%81%97%e3%81%be%e3%81%86/#post-137205)
 * V.J.Catkickさん
 * お返事ありがとうございます。
 * サムネイル画像については、
    記事中の貼り付けられている画像を、 上限4枚まで表示
   をさせたいのです。
 *  トピック投稿者 [モグラ](https://ja.wordpress.org/support/users/tenpra/)
 * (@tenpra)
 * [15年、 8ヶ月前](https://ja.wordpress.org/support/topic/%e5%90%8c%e3%81%98%e3%82%b5%e3%83%a0%e3%83%8d%e3%82%a4%e3%83%ab%e7%94%bb%e5%83%8f%e3%81%8c%e9%87%8d%e8%a4%87%e3%81%97%e3%81%a6%e8%a1%a8%e7%a4%ba%e3%81%95%e3%82%8c%e3%81%a6%e3%81%97%e3%81%be%e3%81%86/#post-137233)
 * function.phpに下記のコードを入れて、
 *     ```
       function catch_that_image() {
           global $post, $posts;
           $news_img = '';
           ob_start();
           ob_end_clean();
           $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
           $news_img = $matches [1] [0];
   
           if(empty($news_img)){ //Defines a default image
               $news_img = "/images/default.jpg";
           }
           return $news_img;
       }
       ```
   
 * indexに
    `<p><img src="<?php echo catch_that_image(); ?>" /><p>`
 * を入れたら何とか記事中の画像を抽出出来た（たぶん。。）んですが、
    このやり方だ
   と1枚しか表示出来ません。。 上限4枚表示させるにはどの様にしたらよいのでしょう？？
   php初心者なもので、どうしたら良いのか分かりません。。 どなたかご教授頂けると非常
   に助かります＞＜

12件の返信を表示中 - 1 - 12件目 (全12件中)

 トピック「同じサムネイル画像が重複して表示されてしまう」には新たに返信することは
できません。

## タグ

 * [サムネイル](https://ja.wordpress.org/support/topic-tag/%e3%82%b5%e3%83%a0%e3%83%8d%e3%82%a4%e3%83%ab/)
 * [重複](https://ja.wordpress.org/support/topic-tag/%e9%87%8d%e8%a4%87/)

 * フォーラム: [テーマ](https://ja.wordpress.org/support/forum/themes/)
 * 12件の返信
 * 4人の参加者
 * 最後の返信者: [モグラ](https://ja.wordpress.org/support/users/tenpra/)
 * 最後の活動: [15年、 8ヶ月前](https://ja.wordpress.org/support/topic/%e5%90%8c%e3%81%98%e3%82%b5%e3%83%a0%e3%83%8d%e3%82%a4%e3%83%ab%e7%94%bb%e5%83%8f%e3%81%8c%e9%87%8d%e8%a4%87%e3%81%97%e3%81%a6%e8%a1%a8%e7%a4%ba%e3%81%95%e3%82%8c%e3%81%a6%e3%81%97%e3%81%be%e3%81%86/#post-137233)
 * 状態: 解決済

## トピック

### 人気のトピック

### 返信がないトピック

### サポート関連ではないトピック

### 解決済みのトピック

### 未解決のトピック

### すべてのトピック
