get_archives_link

最后更新于:2021-11-26 10:51:02

apply_filters( ‘get_archives_link’, string $link_html, string $url, string $text, string $format, string $before, string $after, bool $selected )

Filters the archive link content.

参数

$link_html

(string)
The archive HTML link content.

$url

(string)
URL to archive.

$text

(string)
Archive text description.

$format

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

$before

(string)
Content to prepend to the description.

$after

(string)
Content to append to the description.

$selected

(bool)
True if the current page is the selected archive.

源文件

文件: gc-includes/general-template.php

View on Trac

function example_get_archives_link($link_html) {
    if (is_day() || is_month() || is_year()) {
        if (is_day()) {
            $data = get_the_time('Y/m/d');
        } elseif (is_month()) {
            $data = get_the_time('Y/m');
        } elseif (is_year()) {
            $data = get_the_time('Y');
        }

        // Link to archive page
        $link = home_url($data);

        // Check if the link is in string
        $strpos = strpos($link_html, $link);

        // Add class if link has been found
        if ($strpos !== false) {
            $link_html = str_replace('<li>', '<li class="current-archive">', $link_html);
        }
    }

    return $link_html;
}
add_filter("get_archives_link", "example_get_archives_link");