php - 如何在 php 页面中插入块代码?
问题描述
我的站点中有这个 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 模板do_blocks()
并将(有效)块内容作为字符串传递,例如:
<?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 - 如何为每个汽车产品添加“预订按钮”?
- python - Basinhopping_bounds() 得到了一个意外的关键字参数“f_new”
- python - 将每个张量值映射到列表中最接近的值
- php - 如何检查 bash 脚本中安装的 composer 包
- model-view-controller - Kendo Grid MVC 左键单击打开上下文菜单
- python - 如何在 Nexmo 中检索可用的电话号码?
- r - 如何使用 for 循环生成随机函数?
- postgresql - Scrapy 中没有名为“psycopg2”的模块错误
- asp.net - 在 ASP.NET 应用程序的控制器方法中获取请求用户
- node.js - 我应该在一个节点端点中打开/关闭不同的 Postgres 连接吗?使用 OOP 进行这项工作