get_the_post_thumbnail example


function the_post_thumbnail( $size = 'post-thumbnail', $attr = '' ) {
    echo get_the_post_thumbnail( null, $size$attr );
}

/** * Updates cache for thumbnails in the current loop. * * @since 3.2.0 * * @global WP_Query $wp_query WordPress Query object. * * @param WP_Query $wp_query Optional. A WP_Query instance. Defaults to the $wp_query global. */
$attr = array(
            'class'           => 'wp-block-cover__image-background',
            'data-object-fit' => 'cover',
        );

        if ( isset( $attributes['focalPoint'] ) ) {
            $object_position              = round( $attributes['focalPoint']['x'] * 100 ) . '% ' . round( $attributes['focalPoint']['y'] * 100 ) . '%';
            $attr['data-object-position'] = $object_position;
            $attr['style']                = 'object-position: ' . $object_position;
        }

        $image = get_the_post_thumbnail( null, 'post-thumbnail', $attr );

        /* * Inserts the featured image between the (1st) cover 'background' `span` and 'inner_container' `div`, * and removes eventual whitespace characters between the two (typically introduced at template level) */
        $inner_container_start = '/<div\b[^>]+wp-block-cover__inner-container[\s|"][^>]*>/U';
        if ( 1 === preg_match( $inner_container_start$content$matches, PREG_OFFSET_CAPTURE ) ) {
            $offset  = $matches[0][1];
            $content = substr( $content, 0, $offset ) . $image . substr( $content$offset );
        }
    } else {
        
$extra_styles .= "height:{$attributes['height']};";
    }

    if ( ! empty( $attributes['scale'] ) ) {
        $extra_styles .= "object-fit:{$attributes['scale']};";
    }

    if ( ! empty( $extra_styles ) ) {
        $attr['style'] = empty( $attr['style'] ) ? $extra_styles : $attr['style'] . $extra_styles;
    }

    $featured_image = get_the_post_thumbnail( $post_ID$size_slug$attr );
    if ( ! $featured_image ) {
        return '';
    }
    if ( $is_link ) {
        $link_target    = $attributes['linkTarget'];
        $rel            = ! empty( $attributes['rel'] ) ? 'rel="' . esc_attr( $attributes['rel'] ) . '"' : '';
        $height         = ! empty( $attributes['height'] ) ? 'style="' . esc_attr( safecss_filter_attr( 'height:' . $attributes['height'] ) ) . '"' : '';
        $featured_image = sprintf(
            '<a href="%1$s" target="%2$s" %3$s %4$s>%5$s%6$s</a>',
            get_the_permalink( $post_ID ),
            esc_attr( $link_target ),
            
$image_style .= sprintf( 'max-width:%spx;', $attributes['featuredImageSizeWidth'] );
            }
            if ( isset( $attributes['featuredImageSizeHeight'] ) ) {
                $image_style .= sprintf( 'max-height:%spx;', $attributes['featuredImageSizeHeight'] );
            }

            $image_classes = 'wp-block-latest-posts__featured-image';
            if ( isset( $attributes['featuredImageAlign'] ) ) {
                $image_classes .= ' align' . $attributes['featuredImageAlign'];
            }

            $featured_image = get_the_post_thumbnail(
                $post,
                $attributes['featuredImageSizeSlug'],
                array(
                    'style' => esc_attr( $image_style ),
                )
            );
            if ( $attributes['addLinkToFeaturedImage'] ) {
                $featured_image = sprintf(
                    '<a href="%1$s" aria-label="%2$s">%3$s</a>',
                    esc_url( $post_link ),
                    esc_attr( $title ),
                    
Home | Imprint | This part of the site doesn't use cookies.