2016-01-06 120 views
0

我有以下代碼:添加PHP代碼到現有的代碼

if(get_field('custom_printing_slider_description')): 
    echo get_field($field_name); 
    endif; 

我想添加到下面的行</h3></div>之間:代碼

$popup .= '<div class="pps-header"><h3 class="pps-title">'.get_the_title($popup_id).'</h3></div>; 

增加直接做不行。

回答

0
  • 你的文件應該以.php
  • 結束不要忘了把<?php?>
  • 之間的PHP代碼確保PHP解釋器安裝
  • if語句是這樣的:

    if(#condition) { 
    //#body 
    } 
    
0

也許你應該試試看就像那樣。我想你忘了給「」

$popup .= "<div class="pps-header"><h3 class="ppstitle">'.get_the_title($popup_id).' 
</h3></div>"; 
0

對,它不會工作,因爲你試圖在變量內回顯。我相信你以後會在某處顯示$ popup。此代碼應工作:

//Add the title 
 
$popup .= '<div class="pps-header"><h3 class="pps-title">' . get_the_title($popup_id) . '</h3>'; 
 

 
//If the field is there 
 
if(get_field('custom_printing_slider_description')) { 
 
\t $popup .= get_field($field_name); //--> add the field to $popup variable 
 
} 
 

 
//Close the open div tag 
 
$popup .= '</div>';
您驗證get_field,如果條件爲真,那麼你添加$ FIELD_NAME

通知,關閉的div if語句後,如果你的條件是不正確的,你正確地關閉標籤。