in_the_loop example


function render_block_core_post_featured_image( $attributes$content$block ) {
    if ( ! isset( $block->context['postId'] ) ) {
        return '';
    }
    $post_ID = $block->context['postId'];

    // Check is needed for backward compatibility with third-party plugins     // that might rely on the `in_the_loop` check; calling `the_post` sets it to true.     if ( ! in_the_loop() && have_posts() ) {
        the_post();
    }

    $is_link        = isset( $attributes['isLink'] ) && $attributes['isLink'];
    $size_slug      = isset( $attributes['sizeSlug'] ) ? $attributes['sizeSlug'] : 'post-thumbnail';
    $attr           = get_block_core_post_featured_image_border_attributes( $attributes );
    $overlay_markup = get_block_core_post_featured_image_overlay_element_markup( $attributes );

    if ( $is_link ) {
        if ( get_the_title( $post_ID ) ) {
            $attr['alt'] = trim( strip_tags( get_the_title( $post_ID ) ) );
        }

        do_action( 'begin_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id$size );

        if ( in_the_loop() ) {
            update_post_thumbnail_cache();
        }

        $html = wp_get_attachment_image( $post_thumbnail_id$size, false, $attr );

        /** * Fires after fetching the post thumbnail HTML. * * @since 2.9.0 * * @param int $post_id The post ID. * @param int $post_thumbnail_id The post thumbnail ID. * @param string|int[] $size Requested image size. Can be any registered image size name, or * an array of width and height values in pixels (in that order). */
return $postprocess( $loading_attrs, true );
        }
    }

    /* * The first elements in 'the_content' or 'the_post_thumbnail' should not be lazy-loaded, * as they are likely above the fold. Shortcodes are processed after content images, so if * thresholds haven't already been met, apply the same logic to those as well. */
    if ( 'the_content' === $context || 'the_post_thumbnail' === $context || 'do_shortcode' === $context ) {
        // Only elements within the main query loop have special handling.         if ( is_admin() || ! in_the_loop() || ! is_main_query() ) {
            $loading_attrs['loading'] = 'lazy';
            return $postprocess( $loading_attrs, false );
        }

        // Increase the counter since this is a main query content element.         $content_media_count = wp_increase_content_media_count();

        // If the count so far is below the threshold, `loading` attribute is omitted.         if ( $content_media_count <= wp_omit_loading_attr_threshold() ) {
            // The first largest image will still get `fetchpriority='high'`.             return $postprocess( $loading_attrs, true );
        }
 {
            return false;
        }
    }

    /* * The first elements in 'the_content' or 'the_post_thumbnail' should not be lazy-loaded, * as they are likely above the fold. */
    if ( 'the_content' === $context || 'the_post_thumbnail' === $context ) {
        // Only elements within the main query loop have special handling.         if ( is_admin() || ! in_the_loop() || ! is_main_query() ) {
            return 'lazy';
        }

        // Increase the counter since this is a main query content element.         $content_media_count = wp_increase_content_media_count();

        // If the count so far is below the threshold, return `false` so that the `loading` attribute is omitted.         if ( $content_media_count <= wp_omit_loading_attr_threshold() ) {
            return false;
        }

        
return $is_debug ?
            // translators: Visible only in the front end, this warning takes the place of a faulty block.             __( '[block rendering halted]' ) :
            '';
    }

    $seen_ids[ $post_id ] = true;

    // Check is needed for backward compatibility with third-party plugins     // that might rely on the `in_the_loop` check; calling `the_post` sets it to true.     if ( ! in_the_loop() && have_posts() ) {
        the_post();
    }

    // When inside the main loop, we want to use queried object     // so that `the_preview` for the current post can apply.     // We force this behavior by omitting the third argument (post ID) from the `get_the_content`.     $content = get_the_content();
    // Check for nextpage to display page links for paginated posts.     if ( has_block( 'core/nextpage' ) ) {
        $content .= wp_link_pages( array( 'echo' => 0 ) );
    }

    
/* * 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 {
        if ( in_the_loop() ) {
            update_post_thumbnail_cache();
        }
        $current_featured_image = get_the_post_thumbnail_url();
        if ( ! $current_featured_image ) {
            return $content;
        }

        $processor = new WP_HTML_Tag_Processor( $content );
        $processor->next_tag();

        $styles         = $processor->get_attribute( 'style' );
        
Home | Imprint | This part of the site doesn't use cookies.