2014-02-19 36 views
1

即時通訊使用ACF中繼器生成列表的結果,這是工作正常。但是,而不是顯示列表值,我想顯示列表標籤。如何ACF列表標籤不值

下面是代碼:

 <ul class="notifications-content"> 
      <?php while(has_sub_field('notification')): 
       $house = get_sub_field('house');  
       $year = get_sub_field('year'); 
       $date = DateTime::createFromFormat('Ymd', get_sub_field('date')); 
       $newDate = date("D j F", strtotime($date->format('d-m-Y'))); 
       ?> 
       <li class="<?php echo safe_url($house); ?> <?php echo $year; ?>"> 
        <h2 class="black"><?php echo str_replace($replace, '', get_sub_field('message')); ?></h2> 
        <h3 class="interstatebold white uppercase"><?php echo $house; echo $year ? ", $year" : ''; echo ' | '.$newDate; ?></h3> 
        <?php echo get_sub_field('urgent') ? '<div class="circle"></div>' : ''; ?> 
       </li> 
      <?php endwhile; ?> 
     </ul> 

如何獲取標籤?

回答

0

而不是使用有子字段,使用get_field('平臺')。將相應的中繼器字段名稱替換爲「平臺」。平臺是中繼器領域的名稱。

通過使用具有key =>值對的foreach循環,您可以獲得關鍵值和值。 嘗試使用以下代碼。

$platforms = get_field('platforms'); 
foreach($platforms as $val){ 
         foreach($val as $key=>$v){ 
          echo $key.'=>'.$v.'<br>'; 
         } 
        } 
1

看看這個官方文檔大約get_field_object

有一個在底部的使用例子:

獲取一個字段對象,並使用它顯示它的價值

$field_name = "text_field"; 
$field = get_field_object($field_name); 

echo $field['label'] . ': ' . $field['value']; 

你可以在你的轉發器中使用它來抓取t你想要的帽子field_object並顯示標籤。

0

你可以用同樣的方式,你會使其通過這些函數調用的字段值(增加的functions.php):


function get_field_label($slug) { 
    $field = get_field_object($slug); 
    return $field['label']; 
} 

用法:

<?php echo get_field_label('field-slug'); ?>


function the_field_label($slug) { 
    $field = get_field_object($slug); 
    echo $field['label']; 
} 

用法:

<?php the_field_label('field-slug'); ?>