teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

ソースコード追記

2016/11/05 12:31

投稿

退会済みユーザー
answer CHANGED
@@ -2,4 +2,30 @@
2
2
 
3
3
  ```PHP
4
4
  <?php if($post->post_excerpt;) : ?>
5
- ````
5
+ ````
6
+
7
+ 追記:
8
+ キャプションありの画像を六枚表示するには、以下のようなコードでいいはずです。
9
+ ```PHP
10
+ <?php
11
+ $myposts = get_posts('post_type=attachment&post_mime_type=image&orderby=rand&numberposts=-1');
12
+ $counter = 0;
13
+ if (have_posts()):
14
+ foreach($myposts as $post) : ?>
15
+
16
+ <?php if($post->post_excerpt) : ?>
17
+
18
+ <div><img class="focusimg" src="<?php echo esc_url(get_template_directory_uri()); ?>/img/common/cover_frame.png">
19
+ <img src="<?php echo wp_get_attachment_url($post->ID); ?>">
20
+ </div>
21
+
22
+ <?php
23
+ $counter++;
24
+ if( $counter == 6 ) break;
25
+ ?>
26
+
27
+ <?php endif; ?>
28
+
29
+ <?php endforeach; ?>
30
+ <?php endif; ?>
31
+ ```