I need to output a different link based on the ACF true/false field.
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? 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']
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
$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()
. 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.