【问题标题】:How can I insert a block code inside a php page? [closed]如何在 php 页面中插入块代码? [关闭]
【发布时间】:2021-03-18 07:44:36
【问题描述】:

我的站点中有这个 front-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

【问题讨论】:

    标签: php wordpress wordpress-gutenberg gutenberg-blocks


    【解决方案1】:

    您可以使用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);
    
        ?>
    

    【讨论】:

    • 嗯,非常感谢你,它工作得很好;)
    猜你喜欢
    • 1970-01-01
    • 2013-09-24
    • 1970-01-01
    • 2012-09-09
    • 2021-06-04
    • 1970-01-01
    • 1970-01-01
    • 2022-01-11
    • 2011-03-15
    相关资源
    最近更新 更多