記事の最初の画像を複数件表示させたい
-
記事の最初の画像を表示させることはできましたが現状は1件取得です。
こちらを最新10件表示させたい場合はどのように記述すればよろしいのでしょうか。
色々試してみたのですがうまくいかず困っています。
おわかりの方がいらっしゃったらお願いいたします。function.php ------------------------- function catch_that_image() { global $post, $posts; $first_img = ''; $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); $first_img = $matches [1] [0]; if(empty($first_img)){ //Defines a default image $first_img = "/images/default.jpg"; } return $first_img; }
表示させるphp内 <?php if ( $first_image = catch_that_image() ) : ?> <div class="box"> <img src="<?php echo $first_image; ?>" width="300" alt="<?php the_title(); ?>" /> </div> <?php endif; ?>
1件の返信を表示中 - 1 - 1件目 (全1件中)
1件の返信を表示中 - 1 - 1件目 (全1件中)
- トピック「記事の最初の画像を複数件表示させたい」には新たに返信することはできません。