get_archives_link

函式
get_archives_link ( $url, $text, $format = 'html', $before = '', $after = '', $selected = false )
引數
  • (string) $url URL to archive.
    Required:
  • (string) $text Archive text description.
    Required:
  • (string) $format Optional. Can be 'link', 'option', 'html', or custom. Default 'html'.
    Required:
    Default: 'html'
  • (string) $before Optional. Content to prepend to the description. Default empty.
    Required:
    Default: (empty)
  • (string) $after Optional. Content to append to the description. Default empty.
    Required:
    Default: (empty)
  • (bool) $selected Optional. Set to true if the current page is the selected archive page.
    Required:
    Default: false
返回值
  • (string) HTML link content for archive.
定義位置
相關方法
get_archivesget_search_linkget_search_feed_linkwp_get_archivesget_post_type_archive_link
引入
1.0.0
棄用
-

get_archives_link: 這個函式根據所提供的引數,返回到一個檔案頁的超連結: 該函式返回一個包含檔案連結的字串。

根據預定義或自定義程式碼檢索檔案連結內容。

格式可以是四種風格中的一種。用於頭部元素的’link’,用於選擇元素的’option’,用於列表(ol或ul HTML元素)的’html’。也支援使用前後引數的自定義內容。

連結’格式使用“HTML元素與**檔案**關係。之前和之後的引數不被使用。文字引數用於描述該連結。

選項”格式使用選項HTML元素,用於選擇元素。其值是url引數,前後引數用於文字描述之間。

html’格式,這是預設的,使用li HTML元素,用於列表HTML元素中。before引數是在連結之前,after引數是在關閉連結之後。

自定義格式在連結(’a’HTML元素)之前使用前引數,在關閉連結標籤之後使用後引數。如果沒有使用上述三個格式的值,則假定為自定義格式。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function get_archives_link( $url, $text, $format = 'html', $before = '', $after = '', $selected = false ) {
$text = wptexturize( $text );
$url = esc_url( $url );
$aria_current = $selected ? ' aria-current="page"' : '';
if ( 'link' === $format ) {
$link_html = "t<link rel='archives' title='" . esc_attr( $text ) . "' href='$url' />n";
} elseif ( 'option' === $format ) {
$selected_attr = $selected ? " selected='selected'" : '';
$link_html = "t<option value='$url'$selected_attr>$before $text $after</option>n";
} elseif ( 'html' === $format ) {
$link_html = "t<li>$before<a href='$url'$aria_current>$text</a>$after</li>n";
} else { // Custom.
$link_html = "t$before<a href='$url'$aria_current>$text</a>$aftern";
}
/**
* Filters the archive link content.
*
* @since 2.6.0
* @since 4.5.0 Added the `$url`, `$text`, `$format`, `$before`, and `$after` parameters.
* @since 5.2.0 Added the `$selected` parameter.
*
* @param string $link_html The archive HTML link content.
* @param string $url URL to archive.
* @param string $text Archive text description.
* @param string $format Link format. Can be 'link', 'option', 'html', or custom.
* @param string $before Content to prepend to the description.
* @param string $after Content to append to the description.
* @param bool $selected True if the current page is the selected archive.
*/
return apply_filters( 'get_archives_link', $link_html, $url, $text, $format, $before, $after, $selected );
}
function get_archives_link( $url, $text, $format = 'html', $before = '', $after = '', $selected = false ) { $text = wptexturize( $text ); $url = esc_url( $url ); $aria_current = $selected ? ' aria-current="page"' : ''; if ( 'link' === $format ) { $link_html = "t<link rel='archives' title='" . esc_attr( $text ) . "' href='$url' />n"; } elseif ( 'option' === $format ) { $selected_attr = $selected ? " selected='selected'" : ''; $link_html = "t<option value='$url'$selected_attr>$before $text $after</option>n"; } elseif ( 'html' === $format ) { $link_html = "t<li>$before<a href='$url'$aria_current>$text</a>$after</li>n"; } else { // Custom. $link_html = "t$before<a href='$url'$aria_current>$text</a>$aftern"; } /** * Filters the archive link content. * * @since 2.6.0 * @since 4.5.0 Added the `$url`, `$text`, `$format`, `$before`, and `$after` parameters. * @since 5.2.0 Added the `$selected` parameter. * * @param string $link_html The archive HTML link content. * @param string $url URL to archive. * @param string $text Archive text description. * @param string $format Link format. Can be 'link', 'option', 'html', or custom. * @param string $before Content to prepend to the description. * @param string $after Content to append to the description. * @param bool $selected True if the current page is the selected archive. */ return apply_filters( 'get_archives_link', $link_html, $url, $text, $format, $before, $after, $selected ); }
function get_archives_link( $url, $text, $format = 'html', $before = '', $after = '', $selected = false ) {
	$text         = wptexturize( $text );
	$url          = esc_url( $url );
	$aria_current = $selected ? ' aria-current="page"' : '';

	if ( 'link' === $format ) {
		$link_html = "t<link rel='archives' title='" . esc_attr( $text ) . "' href='$url' />n";
	} elseif ( 'option' === $format ) {
		$selected_attr = $selected ? " selected='selected'" : '';
		$link_html     = "t<option value='$url'$selected_attr>$before $text $after</option>n";
	} elseif ( 'html' === $format ) {
		$link_html = "t<li>$before<a href='$url'$aria_current>$text</a>$after</li>n";
	} else { // Custom.
		$link_html = "t$before<a href='$url'$aria_current>$text</a>$aftern";
	}

	/**
	 * Filters the archive link content.
	 *
	 * @since 2.6.0
	 * @since 4.5.0 Added the `$url`, `$text`, `$format`, `$before`, and `$after` parameters.
	 * @since 5.2.0 Added the `$selected` parameter.
	 *
	 * @param string $link_html The archive HTML link content.
	 * @param string $url       URL to archive.
	 * @param string $text      Archive text description.
	 * @param string $format    Link format. Can be 'link', 'option', 'html', or custom.
	 * @param string $before    Content to prepend to the description.
	 * @param string $after     Content to append to the description.
	 * @param bool   $selected  True if the current page is the selected archive.
	 */
	return apply_filters( 'get_archives_link', $link_html, $url, $text, $format, $before, $after, $selected );
}

常見問題

FAQs
檢視更多 >