是否可以在do_shortcode()函数中运行循环?
示例:
echo do_shortcode('[iscorrect]'.$text_to_be_wrapped_in_shortcode.'[/iscorrect]');http://codex.wordpress.org/Function_Reference/do_shortcode
我尝试创建一个函数来获取数据并将其放入数组中。然后,对于该数组中的每一项,返回单独的数组值。
示例:
function the_ips(){
$ips = get_ips();
foreach($ips as $ip){
return $ip;
}
}我已经转储了数据数组,以确保其中包含正确的数据。一切都是正确的。它继续在do_shortcode()函数中输出数组的第一个值,但不输出其他值。
以下是我尝试过的方法:
echo do_shortcode('[iscorrect]'.the_ips().'[/iscorrect]');或
$content = '';
$content .= '[iscorrect]';
$ips = get_ips();
foreach($ips as $ip){
$content .= $ip;
}
$content .= '[/iscorrect]';
echo do_shortcode($content);它仍然会继续生成数组的第一个结果,而不会产生其他结果。
发布于 2012-03-02 00:24:32
您对return的调用会立即从函数返回。foreach循环的其余部分永远不会运行。也许你只是想加入ips?
return implode(" ", $ips);或者,作为一个列表:
function the_ips(){
$ips = get_ips();
$output = "<ol>";
foreach($ips as $ip){
$output .= "<li>{$ip}</li>";
}
return $output .= "</ol>";
}https://stackoverflow.com/questions/9519893
复制相似问题