返回介绍

get_archives_link()

发布于 2017-09-10 22:44:13 字数 4281 浏览 1029 评论 0 收藏 0

get_archives_link( string $url,  string $text,  string $format = 'html',  string $before = '',  string $after = '' )

Retrieve archive link content based on predefined or custom code.


description

The format can be one of four styles. The ‘link’ for head element, ‘option’ for use in the select element, ‘html’ for use in list (either ol or ul HTML elements). Custom content is also supported using the before and after parameters.

The ‘link’ format uses the <link> HTML element with the archives relationship. The before and after parameters are not used. The text parameter is used to describe the link.

The ‘option’ format uses the option HTML element for use in select element. The value is the url parameter and the before and after parameters are used between the text description.

The ‘html’ format, which is the default, uses the li HTML element for use in the list HTML elements. The before parameter is before the link and the after parameter is after the closing link.

The custom format uses the before parameter before the link (‘a’ HTML element) and the after parameter after the closing link tag. If the above three values for the format are not used, then custom format is assumed.


参数

$url

(string) (Required) URL to archive.

$text

(string) (Required) Archive text description.

$format

(string) (Optional) Can be 'link', 'option', 'html', or custom.

Default value: 'html'

$before

(string) (Optional) Content to prepend to the description.

Default value: ''

$after

(string) (Optional) Content to append to the description.

Default value: ''


返回值

(string) HTML link content for archive.


源代码

File: wp-includes/general-template.php

function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
	$text = wptexturize($text);
	$url = esc_url($url);

	if ('link' == $format)
		$link_html = "\t<link rel='archives' title='" . esc_attr( $text ) . "' href='$url' />\n";
	elseif ('option' == $format)
		$link_html = "\t<option value='$url'>$before $text $after</option>\n";
	elseif ('html' == $format)
		$link_html = "\t<li>$before<a href='$url'>$text</a>$after</li>\n";
	else // custom
		$link_html = "\t$before<a href='$url'>$text</a>$after\n";

	/**
	 * Filters the archive link content.
	 *
	 * @since 2.6.0
	 * @since 4.5.0 Added the `$url`, `$text`, `$format`, `$before`, and `$after` parameters.
	 *
	 * @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.
	 */
	return apply_filters( 'get_archives_link', $link_html, $url, $text, $format, $before, $after );
}

更新日志

Versiondescription
1.0.0Introduced.

相关函数

Uses

  • wp-includes/formatting.php: esc_url()
  • wp-includes/formatting.php: esc_attr()
  • wp-includes/formatting.php: wptexturize()
  • wp-includes/general-template.php: get_archives_link
  • wp-includes/plugin.php: apply_filters()

Used By

  • wp-includes/general-template.php: wp_get_archives()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文