permalink_anchor

函式
permalink_anchor ( $mode = 'id' )
引數
  • (string) $mode Optional. Permalink mode. Accepts 'title' or 'id'. Default 'id'.
    Required:
    Default: 'id'
定義位置
相關方法
permalink_linkpermalink_single_rssthe_permalink_rssget_permalinkthe_permalink
引入
0.71
棄用
-

permalink_anchor: 這個函式用來為當前文章的固定連結輸出一個錨點標籤。它需要兩個引數。$anchor和$leavename。$anchor引數是可選的,允許你指定錨定標籤的文字。$leavename引數也是可選的,允許你指定是否在固定連結中包括文章名稱。

顯示當前文章的固定連結。

固定模式的標題將使用’a’元素’id’屬性的文章標題。id模式使用’post-‘與文章ID作為’id’屬性。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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;
}
}
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; } }
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;
	}
}

常見問題

FAQs
檢視更多 >