permalink_anchor() - WordPress 函数参考中文文档

返回介绍

permalink_anchor()

发布于 2017-09-11 字数2023 浏览 935 评论 0

permalink_anchor( string $mode = 'id' )

Displays the permalink anchor for the current post.


描述

The permalink mode title will use the post title for the ‘a’ element ‘id’ attribute. The id mode uses ‘post-‘ with the post ID for the ‘id’ attribute.


参数

$mode

(string)
(Optional)
Permalink mode. Accepts ‘title’ or ‘id’.

Default value: ‘id’


源代码

File: wp-includes/link-template.php

function permalink_anchor( $mode = 'id' ) {
	$post = get_post();
	switch ( strtolower( $mode ) ) {
		case 'title':
			$title = sanitize_title( $post->post_title ) . '-' . $post->ID;
			echo '<a id="'.$title.'"></a>';
			break;
		case 'id':
		default:
			echo '<a id="post-' . $post->ID . '"></a>';
			break;
	}
}

更新日志

Version 描述
0.71 Introduced.

相关函数

Uses

  • wp-includes/formatting.php:
    sanitize_title()
  • wp-includes/post.php:
    get_post()

User Contributed Notes

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Basic Example

    Inserts the permalink anchor next to a post’s title.

    
    <h3><?php permalink_anchor(); ?><?php the_title(); ?></h3>
    

上一篇:path_join()

下一篇:permalink_link()

发布评论

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

目前还没有任何评论,快来抢沙发吧!