2016-11-23 6 views
0

アドバンスドカスタムフィールドを使用してWPページを作成しています。 - テキストフィールド Columnsection - left_colとright_colと呼ばれる2 WYSIWYGフィールドが含まれていrepeaterfieldACFフィールドを変数に格納

タイトル: は、私は2つのフィールドで構成されていFIELDGROUPを持っています。

だから、結果は次のようになります。

$titles = all Titles 
$left_col = all left_cols 
$right_col = all right_cols 

:そう私は私のテンプレートでやろうとしていますが、すべての値を保持する三つの変数を作成することで、

Cars (title) 
image of a volvo (left_col)  text about a volvo(right_col) 
image of a BMW (left_col)   text about a BMW(right_col) 
image of a Fiat (left_col)   text about a Fiat(right_col) 

[OK]をFIELDGROUPは私が行うことができますrepeaterと呼ばれている:

<?php 
while(have_rows('repeater')): the_row();         
     $title = get_sub_field('main_title'); 
     $rows = get_sub_field('column_section'); 
     $left = $rows['left_column']; 
     $right = $rows['right_column']; 
     echo $title; // Title echoes out 
     echo $left; // nothing (expecting array of left_cols 'related to the title') 
     echo $right; //nothing (expecting array of right_cols 'related to the title') 
     ?> 

理由イムトンをやろうとしています彼は、テンプレートの別の場所でそれらを使用するために、私はright_columnsとleft_columnsを分けたいと思っています。

ヘルプありがとうございます。ありがとうございました!

+0

は、ネストされたリピータについてのドキュメントを見てください:https://www.advancedcustomfields.com/resources/working-with-nested-repeaters/ – Jrod

答えて

0

ネストされたリピータの正しい構文を使用する必要があります。

<?php 
while (have_rows('repeater')): the_row();         
    $title = get_sub_field('main_title'); 
    echo $title; // Title echoes out 

    while (have_rows('column_section')) : the_row(); 

     $left = get_sub_field('left_column '); 
     $right = get_sub_field('right_column '); 

     echo $left; // nothing (expecting array of left_cols 'related to the title') 
     echo $right; //nothing (expecting array of right_cols 'related to the title') 

    endwhile; 

endwhile; 

あなたはここに公式ドキュメントを表示することができます。 https://www.advancedcustomfields.com/resources/working-with-nested-repeaters/

関連する問題