【发布时间】:2013-10-08 18:02:21
【问题描述】:
我有这个用于里程碑式 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>';
?
谢谢!
【问题讨论】:
-
data-perc的值是多少?$count变量是什么?请...真的read the notes,并且不要使用extract -
尝试在 $count 后附加 % 符号..
-
您是说在 $rnr_milestone_box 中附加 % 符号;变量?
-
我认为我没有正确附加,因为没有显示它,你能给我一个正确的附加例子吗?
标签: php html wordpress symbols