如何使用if else语句在wordpress中工作

时间:2013-11-28 11:41:36

标签: php wordpress if-statement

我正在尝试制作if语句,如果填充元数据字段而不是发布youtube视频,如果不是在我的单个wordpress帖子页面上发布特色图像。我是If else语句的新手,所以我不确定我的语法是否正确,因为我不断收到错误。

<?php if ( get_post_meta($post->ID, 'post-video', true) ) : ?>
     <?php $youtube = get_post_meta($post->ID, 'post-video', true);
     echo '<object width="720" height="405"><param name="movie" value="http://www.youtube.com/v/' . $youtube . '?version=3&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' . $youtube . '?version=3&hl=en_US" type="application/x-shockwave-flash" width="720" height="405" allowscriptaccess="always" allowfullscreen="true"></embed></object>';
     ?>
     <?php else 
        the_post_thumbnail('full'); 

    <?php endif; ?>

3 个答案:

答案 0 :(得分:1)

使用<?php else:代替<?php else

希望会奏效!

答案 1 :(得分:0)

If (xxx) {
   // your code if true
} else {
   // your code if false
}

http://php.net/manual/fr/control-structures.elseif.php

答案 2 :(得分:0)

<?php 
if (get_post_meta($post->ID, 'post-video', true)){ 
    $youtube = get_post_meta($post->ID, 'post-video', true)
    echo '<object width="720" height="405"><param name="movie" value="http://www.youtube.com/v/' . $youtube . '?version=3&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' . $youtube . '?version=3&hl=en_US" type="application/x-shockwave-flash" width="720" height="405" allowscriptaccess="always" allowfullscreen="true"></embed></object>';
} else { 
    the_post_thumbnail('full'); 
}
?>