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

質問編集履歴

1

get_fieldの中の値を変更しました。

2021/02/13 02:53

投稿

mido0webdesign
mido0webdesign

スコア0

title CHANGED
File without changes
body CHANGED
@@ -40,4 +40,31 @@
40
40
  endwhile;
41
41
  endif;
42
42
  ?>
43
+ ```
44
+
45
+ if (get_field('image-set')で、2つの内どちらかに画像がアップされている場合は、としていたのですが、これをimage-setというグループ名ではなく、if (get_sub_field('image-pc'))というカスタムフィールド名に変更したら、うまく反映されました。グループ名を指定して、その中が空欄だったらという条件分岐はできないのでしょうか?
46
+
47
+ ```PHP
48
+ ...(略)...
49
+ <?php
50
+ if (have_rows('image-set')):
51
+ while (have_rows('image-set')): the_row();
52
+ if(get_sub_field('image-pc')): // ←変更点
53
+ ?>
54
+ <div class="img-box">
55
+ <?php
56
+ $image_id = get_sub_field('image-pc');
57
+ $_image = wp_get_attachment_image_src($image_id, "none");
58
+ ?>
59
+ <div class="img-pc"><?php echo '<img src="'.$_image[0].'" width="100%" />'; ?></div>
60
+ <?php
61
+ $image_id = get_sub_field('image-sp');
62
+ $_image = wp_get_attachment_image_src($image_id, "none");
63
+ ?>
64
+ <div class="img-sp"><?php echo '<img src="'.$_image[0].'" width="100%" />'; ?></div>
65
+ </div>
66
+ <?php endif;
67
+ endwhile;
68
+ endif;
69
+ ?>
43
70
  ```