1

我目前正在开发一个 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 文件。在我的情况下这似乎是不可能的,因为模板是相同的,所以它不起作用。

4

0 回答 0