我运行的元素在 Google 表格中有一个数据库。我需要在交互式表格中显示该信息。
我使用 Sheetrock.js 和 Handlebar.js 来执行此操作(我编写了代码,它按我希望的方式工作)。我有一个 WordPress 网站,我想制作一个插件,我在其中键入简码,然后我编码的表格出现在页面上。
我有一个带有嵌入式样式的单独 HTML 文件(在 <style></style>
标签下,没有外部 css 文件)。该文件有一个 HTML 样板,并且在 <head></head>
中有指向 sheetrock.js、handlebar.js 和 bootstrap 的链接。
据我了解,php 无法显示那些 HTML 标记? 我尝试执行以下操作...
<?php
function showIco() {
?>
<!DOCTYPE html>
<head>
<!-- all the CDN links -->
</head>
<style>
<!-- all the styling is here, and I know, it's not DRY -->
</style>
<body>
<!-- The content I want to display (it has <script> tags, and variables) -->
</body>
</html>
<?php
return showIco();
}
add_shortcode ('add_ico','showIco');
?>
也许我做错了什么简码根本不显示内容。我需要做什么才能完成这项工作?
最佳答案
您正在返回函数,这会导致递归。
尝试:
<?php
function showIco() {
ob_start();
?>
<!DOCTYPE html>
<head>
all the CDN links
</head>
<style>
all the styling is here, and I know, it's not DRY
</style>
<body>
The content I want to display (it has <script> tags, and variables)
</body>
</html><?php
return ob_get_clean();
}
add_shortcode ('add_ico','showIco');
?>
关于php - Wordpress- 一个使用短代码显示 HTML 内容(数据库)的插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45780206/