[英]if else in php echo (acf true/false condition)
I need to output a different link based on the ACF true/false field. 我需要根据ACF true / false字段输出其他链接。
This is my code: 这是我的代码:
$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>';
How could I do a if/else statement within this output? 如何在此输出中执行if / else语句? I've already read about ternary operators in a other post, but I don't know how to do this my case..
我已经在另一篇文章中阅读了有关三元运算符的信息,但是我不知道该如何做。
You didn't specify where ACL is defined so I'll assume it's in $field['asf']
您没有指定ACL的定义位置,因此我假设它位于
$field['asf']
then 然后
<a class="map-button" href="'. $field['asf'] ? get_permalink() : get_other_link() .'">
When $field['asf']
equals true then get_permalink()
will be invoked otherwise get_other_link()
will be invoked 当
$field['asf']
等于真,那么get_permalink()
将被调用,否则get_other_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;
You can try these functions ob_start()
and ob_get_clean()
. 您可以尝试使用这些函数
ob_start()
和ob_get_clean()
。 Here is the code: 这是代码:
<?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 code given within these functions can be stored in a variable. 这些函数中提供的HTML代码可以存储在变量中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.