我有一個PHP if else
聲明,但它似乎並沒有工作,我不知道爲什麼。PHP的WordPress如果不工作意外的語法
這裏是我的代碼
<?php
if (has_post_thumbnail()) {
?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
<?php
the_post_thumbnail('full', array('class' => 'img-responsive alignleft'));
?>
</a>
<?php
} else() {
?>
<img src="<?php echo get_template_directory_uri(); ?>/images/thumb.png" />';
<?php
}
?>
這裏是我得到語法錯誤,意想不到的,我不知道在哪裏意外)是來自錯誤「)」
。
我在此基礎上構造我的PHP,但是編輯它,因爲我希望能夠把我的成HTML,而不使用echo
<?php if ('' != get_the_post_thumbnail()) {
// some code
}
else {
// some code
}
?>
我很確定在PHP中不允許有空'elseif'。 else()都不是。 – NorthBridge