如何在 php 页面中插入块代码?

How can I insert a block code inside a php page?

我的站点中有这个前 page.php 页面,我想直接在 php 页面中放置一个块代码。所以我得到了一个 div 并且我想把它放在那里。但是代码就像

<!-- wp:latest-posts {"postsToShow":3,"displayPostContent":true,"excerptLength":30,"displayPostDate":true,"postLayout":"grid","displayFeaturedImage":true,"featuredImageSizeSlug":"large","align":"wide","className":"tw-mt-8 tw-img-ratio-3-2 tw-stretched-link is-style-default"} /-->

它来自一个小部件。我无法让它工作请帮忙:D

您可以使用函数 do_blocks() 并将(有效的)块内容作为字符串传递到任何 php 模板中,例如:

    <?php

    $block_content = '<!-- wp:latest-posts {"postsToShow":3,"displayPostContent":true,"excerptLength":30,"displayPostDate":true,"postLayout":"grid","displayFeaturedImage":true,"featuredImageSizeSlug":"large","align":"wide","className":"tw-mt-8 tw-img-ratio-3-2 tw-stretched-link is-style-default"} /-->';
    
    echo do_blocks($block_content);

    ?>