I searched alot and could not find a solution besides writing bigger code. What i request is only to be outputted if one of the two $btn_ strings is set.
In current state if $btn_orange = get_field('btn_orange') equeals true, ( $btn_black = get_field('btn_black') is not being processed while get_field('btn_black') returns a good value.
In short: $btn_black is not set if $btn_orange is.
This is my current code:
<?php if( ( $btn_orange = get_field('btn_orange') ) || ( $btn_black = get_field('btn_black') ) ): ?>
<div class="buttons">
<?php if($btn_orange && ( $btn_orange_url = get_field('btn_orange_url') ) ): ?>
<a class="btn btn-lg btn-primary" href="<?php echo $btn_orange_url; ?>"><?php echo $btn_orange; ?></a>
<?php elseif($btn_orange): ?>
<span class="btn btn-lg btn-primary"><?php echo $btn_orange; ?></span>
<?php endif;?>
<?php if($btn_black && ( $btn_black_url = get_field('btn_black_url') ) ): ?>
<a class="btn btn-lg btn-black" href="<?php echo $btn_black_url; ?>"><?php echo $btn_black; ?></a>
<?php elseif($btn_black): ?>
<span class="btn btn-lg btn-black"><?php echo $btn_black; ?></span>
<?php endif;?>
</div>
<?php endif; ?>
Now i could seperate btn_orange and $btn_black in seperate if blocks. But i only need <div class="buttons"> to be out putted if one of the two or both are set with the values of get_field().
can i accomplish this within the first if statement?
Aucun commentaire:
Enregistrer un commentaire