我正在尝试将if语句添加到锚中。
<div class="box-button">
<a href="
<?php $header_button = of_get_option('header_text'); ?>
<?php if($header_button){?>
<?php echo of_get_option('header_text'); ?>
<?php } else { ?>
#
<?php } ?>
" class="button">Connect Now</a>
</div>
我可以单击主页上的按钮,我将链接到“#”,因此就好像wordpress无法识别为主题选项。我的语法是问题吗?
答案 0 :(得分:1)
您知道可以在html之外执行逻辑,然后将结果插入到href
中<?php
$header_button = of_get_option('header_text');
$link = (!empty($header_button)?$header_button:'#');
?>
<div class="box-button">
<a href="<?php echo $link;?>" class="button">Connect Now</a>
</div>