LoginSignup
0
0

More than 3 years have passed since last update.

【Wordpress】繰り返しフィールドでコンテンツを表示させる

Posted at

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 
}
?>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0