Php 锚定中的if语句
我正在尝试向锚添加一个if语句,就像这样Php 锚定中的if语句,php,wordpress,anchor,Php,Wordpress,Anchor,我正在尝试向锚添加一个if语句,就像这样 <div class="box-button"> <a href=" <?php $header_button = of_get_option('header_text'); ?> <?php if($header_button){?> <?php echo
<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无法识别主题选项一样。我的语法有问题吗 您知道可以在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>
为什么你不只是回显$header\u按钮
,而不是重复的\u get\u选项(“header\u text”)
?为什么你在其中的每一行上都打开和关闭php,而不至少在中间添加任何内容?只需打开一次,完成所有代码,然后在最后关闭。