php - Wordpress- 一个使用短代码显示 HTML 内容(数据库)的插件

标签 php html css wordpress

我运行的元素在 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/

相关文章:

php - Jquery/PHP if 语句拖放更新数组并插入到 MySQL 表中?

php - LIKE查询无法检索数据,为什么?

HTML First column wise 着色和对齐中心

html - 如何将网站表中的数据加载到 R 环境中?

输入上的 JavaScript 更改事件[类型 ="file"]

HTML/CSS 如何纠正重叠的两个列表元素?

php - 登录laravel 5后如何获取 session 内存?

php - 使用 PHP 刷新页面

css - 如何在 CSS 中定义字体粗细?

css - 4 个固定宽度的列,左上角的框跨越 2 列。居中。如何?