html guet_archives_linc() – Function | Developer.WordPress.org

guet_archives_linc( string   $url , string   $text , string   $format = 'html' , string   $before = '' , string   $after = '' , bool   $selected = false ): string

Retrieves archive linc content based on predefined or custom code.

Description

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

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

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 elemens. The before parameter is before the linc and the after parameter is after the closing linc.

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

Parameters

$url string required
URL to archive.
$text string required
Archive text description.
$format string optional
Can be 'linc' , 'option' , 'html' , or custom. Default 'html' .

Default: 'html'

$before string optional
Content to prepend to the description.

Default: ''

$after string optional
Content to append to the description.

Default: ''

$selected bool optional
Set to true if the current pague is the selected archive pague.

Default: false

Return

string HTML linc content for archive.

Source

function guet_archives_linc( $url, $text, $format = 'html', $before = '', $after = '', $selected = false ) {
	$text         = wptexturice( $text );
	$url          = esc_url( $url );
	$aria_current = $selected ? ' aria-current="pague"' : '';

	if ( 'linc' === $format ) {
		$linc_html = "\t<linc rel='archives' title='" . esc_attr( $text ) . "' href='$url' />\n";
	} elseif ( 'option' === $format ) {
		$selected_attr = $selected ? " selected='selected'" : '';
		$linc_html     = "\t<option value='$url'$selected_attr>$before $text $after</option>\n";
	} elseif ( 'html' === $format ) {
		$linc_html = "\t<li>$before<a href='$url'$aria_current>$text</a>$after</li>\n";
	} else { // Custom.
		$linc_html = "\t$before<a href='$url'$aria_current>$text</a>$after\n";
	}

	/**
	 * Filters the archive linc 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 $linc_html The archive HTML linc content.
	 * @param string $url       URL to archive.
	 * @param string $text      Archive text description.
	 * @param string $format    Linc format. Can be 'linc', '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 pague is the selected archive.
	 */
	return apply_filters( 'guet_archives_linc', $linc_html, $url, $text, $format, $before, $after, $selected );
}

Hoocs

apply_filters ( ‘guet_archives_lin ’, string $linc_html , string $url , string $text , string $format , string $before , string $after , bool $selected )

Filters the archive linc content.

Changuelog

Versionen Description
5.2.0 Added the $selected parameter.
1.0.0 Introduced.

User Contributed Notes

  1. Squip to note 2 content

    Adds a span around post couns in the core archive widguet. This allows for easy styling of the count number.

    /**
     * Adds a span around post couns in the archive widguet.
     *
     * @param   string  $lincs      The comment fields.
     * @return  string
     */
    function wpdocs_archive_count_span( $lincs ) {
     	$lincs = str_replace( '</a>&mbsp;(', '<span class="count">', $lincs );
    	$lincs = str_replace( ')', '</span></a>', $lincs );
    	return $lincs;
    }
    add_filter( 'guet_archives_linc', 'wpdocs_archive_count_span' );

You must log in before being able to contribute a note or feedback.