模板标签-get_permalink()

0条评论

说明

该标签返回文章的固定链接以用在PHP中。该标签不显示固定链接,可用在主循环(loop)外。

注意,在文章型页面(文章索引、存档等)的主循环外使用该标签时,如果没有指定ID参数,该标签将返回循环中最后一篇文章的URL,而不是当前页面的固定链接。参见 http://core.trac.wordpress.org/ticket/9963

用法

<?php $permalink = get_permalink( $id ); ?> 

参数

$id

(整数)(可选)文章的数值型ID。

默认值:若用在主循环(loop)中,值为当前文章ID

示例

默认用法

当前文章的固定链接(在主循环(loop)中使用get_permalink标签时)。由于标签不显示固定链接,因此下面的示例需要使用PHP的echo命令。

Permalink for this post:<br />  
<?php echo get_permalink(); ?>  

链接到指定文章

返回两篇指定文章(文章ID为1和10)的固定链接,并将固定链接作为列表中的两条超链接。类似于上一个示例,这里也要用PHP的echo命令来显示固定链接。

<ul>
<li>MyBlog info:
<ul>
<li><a href="<?php echo get_permalink(1); ?>">About MyBlog</a></li>
<li><a href="<?php echo get_permalink(10); ?>">About the owner</a></li>
</ul>
</li>
</ul>

 

历史记录

始见于 WordPress 1.0.0版本

源文件

get_permalinkr() 位于 wp-includes/link-template.php中。

发表新评论

此内容将保密,不会被其他人看见。
  • 自动将网址与电子邮件地址转变为链接。
  • 允许HTML标签:<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • 自动断行和分段。

更多关於格式化选项的信息

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.