php - Wordpress:回显当前帖子永久链接

标签 php wordpress

我编写了社交分享按钮,我想在其中将 single.php 模板中的当前帖子链接到社交媒体分享链接。

当我附加永久链接以共享 url 时出现问题,它没有给出帖子的完整 url:

我试过了 http://twitter.com/share?url=<?php the_permalink() ?>但只给出了 /post/69 的输出不是 http://example.com/post/69 .

有什么建议吗?

最佳答案

在 post 循环之外,您可以为此使用 wordpress get_permalink() 函数。在循环中,您可以使用 the_permalink($post->ID) 尽管这会直接呼应 url。这是来自 wordpress.org 的引用。

https://developer.wordpress.org/reference/functions/get_permalink/ https://codex.wordpress.org/Function_Reference/the_permalink

关于php - Wordpress:回显当前帖子永久链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34789792/

相关文章:

php - OOP中的静态函数有什么用?

php - .php 文件未在所有浏览器中查看

php - 使用php从数据库获取数据到html表

php - 如何将值导入 cssstyle.php 文件?

wordpress - wp-bakery 的位置和文件夹名称

php - 使用社区 SDK 与 Google、Facebook、Twitter 进行身份验证

php - 从 url 中获取元描述、标题和图像,如 facebook 链接共享

mysql - "Insert if doesn' t 在 post_meta 表 WP 中存在 "only for product type = ' 产品

javascript - the_content() 没有正确显示描述

html - 这个翻车是怎么回事?