如何在wordpress的循环之外获取页面固定链接和标题。
我有一个类似这样的函数
function get_post_info(){
$post;
$permalink = get_permalink($post->ID);
$title = get_the_title($post->ID);
return $post_info('url' => $permalink, 'title' => $title);
}当在循环中调用此函数时,它将返回帖子的标题和url。
当它在循环外部调用时。它不会返回当前页面的标题和url。在主页中调用时,它应返回主页的标题和url
怎么会变成这样呢?相反,此函数返回最新的帖子标题和url。
发布于 2010-06-13 19:48:52
经过研究,我自己找到了ans
wp_title()将返回页面标题和
返回页面url的$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
发布于 2010-06-13 20:34:37
通过打印未转义的REQUEST_URI,您将使自己面临可能的XSS攻击。
您的函数没有问题,只是缺少global关键字。将$post;更改为global $post;,您就可以开始航行了!
https://stackoverflow.com/questions/3031209
复制相似问题