我正在尝试添加一个简单的链接,该链接从单个帖子返回到新闻(存档)站点。但我想要的是回到现在的帖子中的锚点。
所以代替:
<a href="http://www.example.com/news">Go back</a>
我需要:
<a href="http://www.example.com/news#post-1111">Go back</a>
我想将其添加到单内容.php,那么如何在 php 中创建它?
提前谢谢。
假设你在php文件中的某个地方有post id。
<a href="http://www.example.com/news#post-<?php echo $post_id; ?>">Go back</a>
像这个示例 URL:http://example.com/post?id=1
<?php
$post_id = $_GET['id'];
?>
<a href="http://www.example.com/news#post-<?php echo $post_id; ?>">Go back</a>
像这样使用它
$post_id 是您当前的帖子 ID。
<a href="http://www.example.com/news#post-<?php echo $post_id; ?>">Go back</a>