Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php echo中的if else(acf真/假条件)_Php_Wordpress_Advanced Custom Fields - Fatal编程技术网

php echo中的if else(acf真/假条件)

php echo中的if else(acf真/假条件),php,wordpress,advanced-custom-fields,Php,Wordpress,Advanced Custom Fields,我需要根据ACF真/假字段输出不同的链接 这是我的代码: $output_map[$the_ID]['map'] = ' <div class="marker" data-lat="'.$get_google_map['lat'].'" data-lng="'.$get_google_map['lng'].'"> <div class="map-wrapper">

我需要根据ACF真/假字段输出不同的链接

这是我的代码:

            $output_map[$the_ID]['map'] = '
                <div class="marker" data-lat="'.$get_google_map['lat'].'" data-lng="'.$get_google_map['lng'].'">
                    <div class="map-wrapper">
                        <div class="map-title">
                            <p><img src="'.$image_url[0].'" alt="'.get_the_title().'"></p>
                            <p class="map-object-title" href="'.get_permalink().'">'.get_the_title().'</p>


IF       <p><a class="map-button" href="'.get_permalink().'">Zum Objekt</a></p>

ELSE     <p>NO LINK</p>




                        </div>
                    </div>
                </div>';
$output\u map[$the\u ID]['map']='

”。获取标题()

如果

ELSE无链接

';

如何在此输出中执行if/else语句?我已经在另一篇文章中读过关于三元运算符的内容,但我不知道如何在我的案例中实现这一点。

您没有指定ACL的定义位置,因此我假设它位于
$field['asf']

然后


$field['asf']
等于true时,将调用
get\u permalink()
,否则将调用
get\u other\u link()
$text = '<div class="marker" data-lat="' . $get_google_map['lat'] . '" data-lng="' . $get_google_map['lng'] . '">
    <div class="map-wrapper">
        <div class="map-title">
            <p><img src="' . $image_url[0] . '" alt="' . get_the_title() . '"></p>
            <p class="map-object-title" href="' . get_permalink() . '">' . get_the_title() . '</p>';

IF $text .= '<p><a class="map-button" href="' . get_permalink() . '">Zum Objekt</a></p>';

ELSE $text .= '<p>NO LINK</p>';

$text .= '</div>
    </div>
</div>';

$output_map[$the_ID]['map'] = $text;

”。获取标题()

",; 如果$text.='

'; ELSE$text.='无链接

'; $text.=' '; $output_map[$the_ID]['map']=$text;
您可以尝试以下功能
ob\u start()
ob\u get\u clean()
。代码如下:

<?php $output_map[$the_ID]['map'] = ''; 
ob_start();
?>
<div class="marker" data-lat="'.$get_google_map['lat'].'" data-lng="'.$get_google_map['lng'].'">
     <div class="map-wrapper">
         <div class="map-title">
             <p><img src="'.$image_url[0].'" alt="'.get_the_title().'"></p>
                <p class="map-object-title" href="'.get_permalink().'">'.get_the_title().'</p>
  <?php if(){?>       
     <p><a class="map-button" href="'.get_permalink().'">Zum Objekt</a></p>
  <?php }else{?>
    <p>NO LINK</p>
  <?php } ?>
     </div>
   </div>
</div>
<?php 
$output_map[$the_ID]['map'] = ob_get_clean();
?>

”。获取标题()

无链接


这些函数中给出的Html代码可以存储在变量中

非常感谢你!工作得很卖力
<?php $output_map[$the_ID]['map'] = ''; 
ob_start();
?>
<div class="marker" data-lat="'.$get_google_map['lat'].'" data-lng="'.$get_google_map['lng'].'">
     <div class="map-wrapper">
         <div class="map-title">
             <p><img src="'.$image_url[0].'" alt="'.get_the_title().'"></p>
                <p class="map-object-title" href="'.get_permalink().'">'.get_the_title().'</p>
  <?php if(){?>       
     <p><a class="map-button" href="'.get_permalink().'">Zum Objekt</a></p>
  <?php }else{?>
    <p>NO LINK</p>
  <?php } ?>
     </div>
   </div>
</div>
<?php 
$output_map[$the_ID]['map'] = ob_get_clean();
?>