Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



wp_get_attachment_link ›

Seit2.5.0
Veraltetn/v
wp_get_attachment_link ( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false )
Parameter: (5)
  • (int|WP_Post) $id Optional. Post ID or post object.
    Erforderlich: Nein
    Standard:
  • (string) $size Optional, default is 'thumbnail'. Size of image, either array or string.
    Erforderlich: Nein
    Standard: 'thumbnail'
  • (bool) $permalink Optional, default is false. Whether to add permalink to image.
    Erforderlich: Nein
    Standard: false
  • (bool) $icon Optional, default is false. Whether to include icon.
    Erforderlich: Nein
    Standard: false
  • (string|bool) $text Optional, default is false. If string, then will be link text.
    Erforderlich: Nein
    Standard: false
Nutzt:
Gibt zurück:
  • (string) HTML content.
Definiert in:
Codex:

Retrieve an attachment page link using an image or icon, if possible.



Quellcode

function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false ) {
	$id = intval( $id );
	$_post = get_post( $id );

	if ( empty( $_post ) || ( 'attachment' != $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) )
		return __( 'Missing Attachment' );

	if ( $permalink )
		$url = get_attachment_link( $_post->ID );

	if ( $text )
		$link_text = $text;
	elseif ( $size && 'none' != $size )
		$link_text = wp_get_attachment_image( $id, $size, $icon );
	else
		$link_text = '';

	if ( trim( $link_text ) == '' )
		$link_text = $_post->post_title;

	/**
	 * Filter a retrieved attachment page link.
	 *
	 * @since 2.7.0
	 *
	 * @param string      $link_html The page link HTML output.
	 * @param int         $id        Post ID.
	 * @param string      $size      Image size. Default 'thumbnail'.
	 * @param bool        $permalink Whether to add permalink to image. Default false.
	 * @param bool        $icon      Whether to include an icon. Default false.
	 * @param string|bool $text      If string, will be link text. Default false.
	 */
	return apply_filters( 'wp_get_attachment_link', "<a href='$url'>$link_text</a>", $id, $size, $permalink, $icon, $text );
}