2016-01-06 55 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语句后,如果你的条件是不正确的,你正确地关闭标签。