1
我试图发布一个输出的变化是基于变量是否为true,但在foreach循环中插入if语句后没有任何显示。我错过了什么?PHP如果为True返回false
$odd = TRUE;
foreach ($recent as $item) {
if ($odd == TRUE) {
$out .= '<div class="col-sm-12 col-md-6">';
$out .= '<a href="' . get_permalink($item['ID']) . '">';
$out .= get_the_post_thumbnail($item['ID']);
$out .= '</a>';
$out .= '</div><div class="col-sm-12 col-md-6">';
$out .= get_the_excerpt($item['ID']);
$out .= '</div>';
return FALSE;
} else {
$out .= '<div class="col-sm-12 col-md-6">';
$out .= get_the_excerpt($item['ID']);
$out .= '</a>';
$out .= '</div><div class="col-sm-12 col-md-6">';
$out .= '<a href="' . get_permalink($item['ID']) . '">';
$out .= get_the_post_thumbnail($item['ID']);
$out .= '</div>';
return TRUE;
}
}
你知道'return'的作用,对吗? – Federkun
你在哪里打印'$ out'变量? –
删除返回并使用echo退出语句 – RJParikh