モグラ
フォーラムへの返信
-
フォーラム: テーマ
返信が含まれるトピック: 同じサムネイル画像が重複して表示されてしまう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初心者なもので、どうしたら良いのか分かりません。。
どなたかご教授頂けると非常に助かります><フォーラム: テーマ
返信が含まれるトピック: 同じサムネイル画像が重複して表示されてしまうV.J.Catkickさん
お返事ありがとうございます。
サムネイル画像については、
記事中の貼り付けられている画像を、
上限4枚まで表示をさせたいのです。フォーラム: テーマ
返信が含まれるトピック: 同じサムネイル画像が重複して表示されてしまう管理人さん、移動ありがとうございます。
お手数おかけしました。tmatsuurさん
お返事ありがとうございます。
すみません、先ほどお名前間違えてました。。
tmatsuurさんのご指摘通り「ライブラリ」に同じ画像が3つ画像がアップされていました。
原因がわかったので非常に助かりました><
そうなると、記事中に貼り付けられている画像だけを呼び出すようするには、
どのような記述で引っ張り出せば良いでしょう??ご教授頂けると助かります><;フォーラム: テーマ
返信が含まれるトピック: 同じサムネイル画像が重複して表示されてしまう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 '-->';画像が出てこなくなってしまいました><
フォーラム: テーマ
返信が含まれるトピック: 同じサムネイル画像が重複して表示されてしまうV.J.Catkickさん
度々お返事有難う御座います。
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を取得しているようです。。。
ますます謎です。。フォーラム: テーマ
返信が含まれるトピック: 同じサムネイル画像が重複して表示されてしまう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;?>何か別の原因なのでしょうか??