php if 和 else 语法错误

php syntax error with if and else

我有以下内容 markup.I 我做不到 work.It 显示语法错误。

if(has_terms( array('something','else'), 'product_cat' ) ) {
   $output .= '<div class="list_image">';
   $output .= '</div>';
}else{
  $output .= '<div class="list_post">';
  $output .= '</div>';
}
endif;

我犯了什么 syntax 错误?

删除 endif; 当你使用大括号时你不需要(也不能使用)endif.

这个:

if (true) {
  echo 'hello';
} else {
  echo 'goodbye';
}

...等同于:

if (true):
  echo 'hello';
else:
  echo 'goodbye';
endif;

不能混用这两种样式。