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

使用php基于url显示/隐藏div,php,url,html,uri,hide,Php,Url,Html,Uri,Hide,我目前正在wordpress网站上工作,我在两个页面上使用相同的页面模板。页面模板文件是single.php。现在我有一个历史回顾按钮,需要在其中一页上,而不是在两页上。我也在用permalinks。既然我不太擅长php,我想请你帮我一下。我已在internet上找到以下代码,但无法使其正常工作: php: <?php if (strpos($_SERVER["REQUEST_URI"], "localhost:8888/sunbook/reader-comments/") >

我目前正在wordpress网站上工作,我在两个页面上使用相同的页面模板。页面模板文件是single.php。现在我有一个历史回顾按钮,需要在其中一页上,而不是在两页上。我也在用permalinks。既然我不太擅长php,我想请你帮我一下。我已在internet上找到以下代码,但无法使其正常工作:

php:

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

我认为问题出在请求的uri中,因为我看到的每个地方都在调用php文件。在我的例子中,这似乎是不可能的,因为模板是相同的,所以它无法工作。

它当前的行为是什么?在PHP
if else
中测试执行了哪个语句。当前它只执行if语句。它应该触发不同行为的两个URL是什么?当前在我的本地主机上:这里不应显示div,另一个是:将您的答案添加到下面作为答案,而不是编辑。谢谢
<div id="historyback" class='<?php echo $historyback_class; ?>'>
    <script>
        function goBack()
        {
            window.history.back()
        }
    </script>

    <input type="button" value="Back" onclick="goBack()">
</div>
#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; }