Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 锚定中的if语句_Php_Wordpress_Anchor - Fatal编程技术网

Php 锚定中的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

我正在尝试向锚添加一个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无法识别主题选项一样。我的语法有问题吗

您知道可以在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,而不至少在中间添加任何内容?只需打开一次,完成所有代码,然后在最后关闭。