Php wordpress中的If/else语句将上载的图像更改为默认值

Php wordpress中的If/else语句将上载的图像更改为默认值,php,wordpress,if-statement,Php,Wordpress,If Statement,当图像字段为空时,我在更改默认图像时遇到一些问题。这里是两个不同的图像。我想合并它们,如果get_字段(“author_photo”)为空,则上传第二个 <?php $image = get_field('author_photo'); if( !empty($image) ): ?> <img src="<?php echo $image['url']; ?>" height="80" id="img-sp" alt=

当图像字段为空时,我在更改默认图像时遇到一些问题。这里是两个不同的图像。我想合并它们,如果get_字段(“author_photo”)为空,则上传第二个

  <?php 
       $image = get_field('author_photo');
       if( !empty($image) ): 
  ?>

  <img src="<?php echo $image['url']; ?>" height="80" id="img-sp" alt="<?php echo $image['alt']; ?>" />

  <?php endif; ?>              

  <? if (get_user_featured_image_id('mentor','user_'.get_the_author_ID())){ ?>
  <?php $image = p_get_attachment_image_src(get_field('user_featured_image', 'user_'.get_the_author_ID()),'small-profile-thumbnail'); 
  ?>

  <img src="<?php echo @$image[0]; ?>" height="80"  alt="" id="img-sp"/>

“height=“80”id=“img sp”alt=”“/>
“height=“80”alt=“”id=“img sp”/>

提前谢谢

昨天解决了。谢谢你的回答

<?php
   $image = get_field('author_photo');
    $src_link = "";
    $alt_text = "";

    if (!empty($image)) {
        $src_link = $image['url'];
        $alt_text = $image['alt'];
    } elseif (get_user_featured_image_id('mentor','user_'.get_the_author_ID())) {
        $image = wp_get_attachment_image_src(get_user_featured_image_id('mentor','user_'.get_the_author_ID()),'small-profile-thumbnail');
        $src_link = @$image[0];
    }

    if ($src_link) { ?>
        <img src="<?php echo $src_link; ?>" height="80" id="img-sp" alt="<?php echo $alt_text; ?>" /><?php
    }
?>

“height=“80”id=“img sp”alt=”“/>

我正试图阅读你的问题,但我无法停止盯着@$image调用。永远不要使用@。它会抑制你应该知道的东西。即使它被抑制,警告也会导致不必要和意外的系统负载。现在我将通读这一行@行不应该是this=“height=”80“alt=”id=“img sp”/>结尾在哪里{第二个如果?我看不到。还有,如果你曾经看到过?>