根据预定义或自定义代码检索存档链接内容。
原型
get_archives_link( string $url, string $text, string $format = 'html', string $before = '', string $after = '' )
描述
格式可以是四种样式之一。 head元素的’link’,select元素中使用’option’,列表中使用’html’(ol或ul HTML元素)。使用before和after参数也支持自定义内容。
参数
$url
(string)
(Required)
要归档的URL。
$text
(string)
(Required)
存档文字说明。
$format
(string)
(Optional)
可以是“链接”,“选项”,“html”或自定义。
$before
(string)
(Optional)
要添加到说明中的内容。
$after
(string)
(Optional)
要附加到说明的内容。
返回值
(string)
用于存档的HTML链接内容。
源文件
路径:wp-includes/general-template.php
<?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>$aftern";
/**
* 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 );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/get_archives_link/