^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_archives_link()用法示例

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

Retrieve archive link content based on predefined or custom code.


描述

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.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包

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 描述.

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 描述.

$format

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

Default value: ‘html’

$before

(string)
(Optional)
Content to prepend to the 描述.

Default value: ”

$after

(string)
(Optional)
Content to append to the 描述.

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 描述.
	 * @param string $format    Link format. Can be 'link', 'option', 'html', or custom.
	 * @param string $before    Content to prepend to the 描述.
	 * @param string $after     Content to append to the 描述.
	 */
	return apply_filters( 'get_archives_link', $link_html, $url, $text, $format, $before, $after );
}

更新日志

Version 描述
1.0.0 Introduced.

相关函数

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()

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈