【发布时间】:2017-07-14 22:34:58
【问题描述】:
我不知道如何将else 添加到foreach!
这是我的代码:
<?php $terms = get_the_terms( $post->ID , 'actor' );
foreach ( $terms as $term ) {
$term_link = get_term_link( $term, 'actor' );
if( is_wp_error( $term_link ) )
continue;
echo '<a href="' . $term_link . '">' . $term->name . '</a>';
}
?>
【问题讨论】:
-
到目前为止,您真的尝试过什么吗?顺便说一句:
foreach不支持else,但if支持。 -
你想在逻辑上实现什么......?
-
@FranzGleichmann - 有趣的是,我最近看到一些建议为
foreach提出了else -
@MarkBaker 我最近看到了类似的东西,我相信它是 twig 的一部分,这不是一个坏主意 - 但到目前为止,大多数语言(包括 PHP)都没有实现任何东西喜欢。