我有这个用于里程碑 wordpress 短代码的 php 代码:
function rocknrolla_milestone_box_shortcode( $atts, $content = null ){
extract( shortcode_atts(array(
"count" => '90%',
"title" => ''
), $atts) );
echo htmlentities($count);
$rnr_milestone_box = '<div class="milestone-counter" data-perc="'. $count .'">';
$rnr_milestone_box .= '<span class="milestone-count highlight">'. $count .'</span>';
$rnr_milestone_box .= '<h6 class="milestone-details">'. $title .'</h6>';
$rnr_milestone_box .= '</div>';
return $rnr_milestone_box;
}
add_shortcode('milestone_box', 'rocknrolla_milestone_box_shortcode');
现在,例如,当我添加“data-perc”属性 99% 时,它会显示一个奇怪的文本,例如:
<span class="milestone-count highlight">NaN</span>
如果我只添加像 99 这样的数字,则输出是正确的:
<span class="milestone-count highlight">99</span>
如何在此处的 count 变量后附加 % 符号:
$rnr_milestone_box .= '<span class="milestone-count highlight">'. $count .'</span>';
?
谢谢!