自动将当前页面的 ID 添加到 href


Automatically add id of current page to href

我在下面有一个链接,因为它可以在特定的WordPress插件中找到:

<a href='".home_url("?p=7&action=get_marks&id=$select_data2->id")."' ></a> 

我想在单击它以重新加载同一页面时自动检测page_id,例如:

 <a href='".home_url("?p=get_id&action=get_marks&id=$select_data2->id")."'></a> 

我不想在输入简码后每次创建新页面时都写页面 ID。

我假设你在谈论服务器端

echo '<a href=".home_url("?p='.$id.'&action=get_marks&id=$select_data2->id")."></a> '

其中$id是具有 id 的变量

你有没有考虑过客户端的JavaScript?

<a href="#" onclick="window.location.reload();"></a>

感谢您的帮助我尝试了几种方法,直到找到解决方案 这里的代码

global $post;
echo '<a href='".home_url("?p=$post->ID&action=get_marks&id=$select_data2->id")."'>';

其中 $post->ID 是具有页面 ID 的变量

谢谢你给我解决问题@user74670灵感