ACFの繰り返しフィールドでコンテンツを表示するには
なお、当記事では以下のように各々命名するとします
フィールド名:
details
サブフィールド:
A.画像(ここではimgと名付ける)
B.タイトル(ここではtitleと名付ける)
C.詳細ページへのURL(ここではpage_urlと名付ける)
1.まずフィールド名からフィールド内のコンテンツを取得します
single.php(例)
<?php
$details = get_field('details');
?>
2.次に各サブフィールドコンテンツを変数に代入します
single.php
<?php
foreach ($details as $detail) {
$img=$detail['img'];
$title=$detail['title'];
$page_url=$detail['page_url'];
?>
3.それぞれ埋め込みたい先に変数を使ってphpを記述します
single.php
Ex) <a href="<?php echo $page_url; ?>">参照したいリンクのページの概要</a>
4.Foreach文の終了宣言をします
single.php
<?php
}
?>