Wordpress 提供了一个名为“the_permalink()”的函数,您猜对了!在帖子循环中返回给定帖子的永久链接。
我正在尝试对该永久链接进行 URL 编码,当我执行此代码时:
<?php
print(the_permalink());
$permalink = the_permalink();
print($permalink);
print(urlencode(the_permalink()));
print(urlencode($permalink));
$url = 'http://wpmu.local/graphjam/2008/11/06/test4/';
print($url);
print(urlencode($url));
?>
它以 HTML 形式生成以下结果:
http://wpmu.local/graphjam/2008/11/06/test4/
http://wpmu.local/graphjam/2008/11/06/test4/
http://wpmu.local/graphjam/2008/11/06/test4/
http://wpmu.local/graphjam/2008/11/06/test4/
http%3A%2F%2Fwpmu.local%2Fgraphjam%2F2008%2F11%2F06%2Ftest4%2F
我希望输出的第 2、3 和 5 行是 URL 编码的,但只有第 5 行是这样的。想法?
根据文档,the_permalink http://codex.wordpress.org/Template_Tags/the_permalink打印永久链接与返回它。所以,urlencode
没有得到任何要编码的东西。
Try get_permalink http://codex.wordpress.org/Template_Tags/get_permalink.
[EDIT]
编辑有点晚了,但我没有意识到打印计数是一个问题。
他们都来自这里:
<?php
print(the_permalink()); // prints (1)
$permalink = the_permalink(); // prints (2)
print($permalink); // nothing
print(urlencode(the_permalink())); // prints (3)
print(urlencode($permalink)); // nothing
$url = 'http://wpmu.local/graphjam/2008/11/06/test4/';
print($url); // prints (4)
print(urlencode($url)); // prints (5)
?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)