怎样在页面之外获取页面的Block

<?php
$post = get_post( 123 ); // Replace 123 with your post ID
if ( ! $post ) {
    return;
}
$blocks = parse_blocks( $post->post_content );
// $blocks is an array of block arrays and text nodes
foreach ( $blocks as $block ) {
    if ( isset( $block['blockName'] ) && $block['blockName'] === 'my-plugin/my-block' ) {
        // Found the block instance
        $html = render_block( $block );
        echo '<div class="outside-container">';
        echo $html;
        echo '</div>';
        // If you only want the first, break here.
    }
}
×
怎样在页面之外获取页面的Block

怎样在页面之外获取页面的Block

<?php $post = get...