WordPress 中的单独评论 URL,用于跨网络的 URI 集成

发布于 2024-12-23 01:33:45 字数 469 浏览 0 评论 0原文

我一直在开发一个评论系统(对 WordPress 进行逆向工程)。就我而言,我希望每条评论都难以被社交网络处理。这意味着他们需要自己的 URL。我构建了一个页面(comment.php)并将评论的 ID 存储为获取参数。

问题在于社交网络删除了 get 参数,以便它们可以在其中存储自己的数据。

然后我使用页码系统将其构建到 URL 中作为评论 id,然后使用 str_replace 来获取我们想要的评论的 id。 (即example.com/comment/135)。这有效,但社交网络删除了页码部分。如果数字后面有字母,他们不会删除它们。

因此,我正在寻找一种拥有单独评论页面的方法。我已经制作了一个主题文件并准备好使用,但我只需要一个有效的标准评论 URL。类似 example.com/comment/135-comment/ 的内容有自己的页面,可以从 URI 中提取 ID。这怎么能做到呢?

I have been developing a comment system (reverse engineering the WordPress one). In my case I want each comment to be intractable with social networks. This means that they need they're own URL. I built a page (comment.php) and stored the ID of the comment as a get parameter.

The problem is that the social networks remove the get parameter so that they can store their own data inside it.

I then built it into the URL using the page numbers system as the comment id and then str_replace to get the id of the comment we want. (i.e. example.com/comment/135). This worked but the social networks removed the page numbers section. They do not remove them if a letter were to sit after the numbers.

Thus I am looking for a way of having individual comment pages. I have a themed file already made and ready to go, but I just need a standard comment URL that works. Something like example.com/comment/135-comment/ with it's own page that can then extract the ID from the URI. How can this be done?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

违心° 2024-12-30 01:33:45

您可以使用 htaccess 规则将 example.com/comment/135-comment 重写为 example.com/comment/?id=135

但这仅在您有相应的情况下才有效。 url example.com/comment/ 中的评论模板

RewriteEngine On
RewriteBase /

RewriteRule ^comment/([0-9]+)-comment/$ http://example.com/comment/?id=$1 [L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

通用方法是使用类似 example.com/123-post/135-comment/ 的内容,同时包含帖子 id 和评论 id。

RewriteEngine On
RewriteBase /

RewriteRule ^([0-9]+)-post/([0-9]+)-comment/$ http://example.com/?p=$1#comment-$2 [L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

应该适用于大多数主题。

You can use htaccess rule to rewrite example.com/comment/135-comment to example.com/comment/?id=135

But this will work only if you have the resp. comment template in the url example.com/comment/

RewriteEngine On
RewriteBase /

RewriteRule ^comment/([0-9]+)-comment/$ http://example.com/comment/?id=$1 [L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

A generic way is to use something like example.com/123-post/135-comment/ with both post id and comment id.

RewriteEngine On
RewriteBase /

RewriteRule ^([0-9]+)-post/([0-9]+)-comment/$ http://example.com/?p=$1#comment-$2 [L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Should work with most themes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文