PHP WordPress如果否则无法使用意外语法

PHP WordPress如果否则无法使用意外语法,php,wordpress,if-statement,Php,Wordpress,If Statement,我有一个PHPif-else语句,但是它似乎不起作用,我不知道为什么 这是我的密码 <?php if (has_post_thumbnail()) { ?> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" > <?php the_post_thumbnail('full', array('cla

我有一个PHP
if-else
语句,但是它似乎不起作用,我不知道为什么

这是我的密码

<?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 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 endif; ?>

/images/thumb.png“/>”;
让我们试试这个:

<?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 endif; ?>

/images/thumb.png“/>”;

我不知道为什么您用这种方式编写代码,而不是将其串联起来,但是您的if-else语句在else“()”后面有两个括号。您可能希望去掉这些来解决问题。

我不确定您为什么用这种方式编写代码,而不是将其串联起来,但是您的if-else语句在else“()”后面有两个括号。你可能想摆脱这些来解决你的问题。

在PHP中,else不是一个函数,所以你不应该像以前那样调用它。

在PHP中,else不是一个函数,所以你不应该像以前那样调用它。

PHP's,
请尝试以下操作:

<?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 { //instead of elseif () here, use else
?> 
    <img src="<?php echo get_template_directory_uri(); ?>/images/thumb.png" />
<?php 
    }
?>

/图像/thumb.png/>
请同时参阅,以使您的代码更易于阅读和维护。在没有清楚标记编辑内容的情况下,尽量不要编辑问题中的原始代码,否则用户将无法理解您的问题/进一步帮助您。

PHP's,
请尝试以下操作:

<?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 { //instead of elseif () here, use else
?> 
    <img src="<?php echo get_template_directory_uri(); ?>/images/thumb.png" />
<?php 
    }
?>

/图像/thumb.png/>

另请参阅以使代码更易于阅读和维护。在没有清楚标记编辑内容的情况下,尽量不要编辑问题中的原始代码,否则用户将无法理解您的问题/进一步帮助您。

我非常确定PHP中不允许使用空的
elseif
else()
都不是。我很确定在PHP中不允许使用空的
elseif
else()
都不可用。