使用php显示/隐藏基于url的div

时间:2013-01-29 20:44:23

标签: php url html uri hide

我目前正在使用wordpress网站,我在两个页面上使用相同的页面模板。页面模板文件是single.php。现在我有一个历史记录后退按钮,需要在其中一个页面上而不是两个页面上。我也在使用永久链接。好吧,因为我不擅长PHP我会要求你帮助我。我已经在互联网上找到了以下代码,但我无法让它工作:

php:

<?php
    if (strpos($_SERVER["REQUEST_URI"], "localhost:8888/sunbook/reader-comments/") >= 0) {
        $historyback_class = "showme";
    }
    else {
        $historyback_class = "hideme";
    }
?>

html:

<div id="historyback" class='<?php echo $historyback_class; ?>'>
    <script>
        function goBack()
        {
            window.history.back()
        }
    </script>

    <input type="button" value="Back" onclick="goBack()">
</div>

css:

#historyback { margin-left: auto; margin-right: auto; width: 95%; max-width: 920px; color: #bfbfbf; font-size: 23px; font-family: 'RobotoLight', Arial, sans-serif; line-height: 28px; margin-bottom: 0px; }
.hideme { display: none; }
.showme { display: block; }

我认为问题出现在请求的uri中,因为我看到他们正在调用一个php文件。在我的情况下,这似乎是不可能的,因为模板是相同的,所以它不会起作用。

0 个答案:

没有答案