get_archives_link()
最后更新于:2021-11-26 04:18:22
get_archives_link( string$url, string$text, string$format=’html’, string$before=”, string$after=”, bool$selected=false)Retrieve archive link content based on predefined or custom code.
参数
- $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: ”
- $selected
-
(bool) (Optional) Set to true if the current page is the selected archive page.
Default value: false
响应
(string) HTML link content for archive.
源文件
文件: gc-includes/general-template.php
function get_archives_link( $url, $text, $format = 'html', $before = '', $after = '', $selected = false ) {
$text = gctexturize( $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='https://docs.gechiui.com/functions/get_archives_link/$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='https://docs.gechiui.com/functions/get_archives_link/$url'$aria_current>$text</a>$after</li>n";
} else { // Custom.
$link_html = "t$before<a href='https://docs.gechiui.com/functions/get_archives_link/$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 );
}