如何在 php 页面中插入块代码? [关闭]
Posted
技术标签:
【中文标题】如何在 php 页面中插入块代码? [关闭]【英文标题】:How can I insert a block code inside a php page? [closed] 【发布时间】: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
【问题讨论】:
【参考方案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);
?>
【讨论】:
嗯,非常感谢你,它工作得很好;)以上是关于如何在 php 页面中插入块代码? [关闭]的主要内容,如果未能解决你的问题,请参考以下文章