回答編集履歴

1

ソースコード追記

2016/11/05 12:31

投稿

退会済みユーザー
test CHANGED
@@ -7,3 +7,55 @@
7
7
  <?php if($post->post_excerpt;) : ?>
8
8
 
9
9
  ````
10
+
11
+
12
+
13
+ 追記:
14
+
15
+ キャプションありの画像を六枚表示するには、以下のようなコードでいいはずです。
16
+
17
+ ```PHP
18
+
19
+ <?php
20
+
21
+ $myposts = get_posts('post_type=attachment&post_mime_type=image&orderby=rand&numberposts=-1');
22
+
23
+ $counter = 0;
24
+
25
+ if (have_posts()):
26
+
27
+ foreach($myposts as $post) : ?>
28
+
29
+
30
+
31
+ <?php if($post->post_excerpt) : ?>
32
+
33
+
34
+
35
+ <div><img class="focusimg" src="<?php echo esc_url(get_template_directory_uri()); ?>/img/common/cover_frame.png">
36
+
37
+ <img src="<?php echo wp_get_attachment_url($post->ID); ?>">
38
+
39
+ </div>
40
+
41
+
42
+
43
+ <?php
44
+
45
+ $counter++;
46
+
47
+ if( $counter == 6 ) break;
48
+
49
+ ?>
50
+
51
+
52
+
53
+ <?php endif; ?>
54
+
55
+
56
+
57
+ <?php endforeach; ?>
58
+
59
+ <?php endif; ?>
60
+
61
+ ```