如果声明在锚

时间:2013-02-13 00:32:34

标签: php wordpress anchor

我正在尝试将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无法识别为主题选项。我的语法是问题吗?

1 个答案:

答案 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>
相关问题