gpt4 book ai didi

php - 如何强制 wordpress 模板解析代码而不是纯文本

转载 作者:太空宇宙 更新时间:2023-11-04 04:59:43 25 4
gpt4 key购买 nike

我最近在我的 wordpress 博客中安装了一个新模板(更具体地说是 SquirrelTheme - 一个免费模板)。碰巧我想在我的首页上有两个按钮。假设按钮 X 和按钮 Y。为了创建这些按钮,我使用了一个名为“MaxButtons”的插件,它允许您轻松创建和管理按钮及其功能。创建上述按钮后,它会为您提供一个简码,您可以将其插入到您的帖子和页面中 - 让我们说 [maxbutton id="1"] - 以显示它。

不幸的是,根据我的喜好编辑模板后(删除我不打算显示的 div),我似乎无法显示这两个按钮,因为模板解析纯文本,显然与页面/帖子不同。

如果您想知道我是如何插入按钮的简码的,可以通过仪表板轻松修改模板,我在其中的字段中插入了以下内容,指示在主页的特定部分显示的内容:

[maxbutton id="1"]  [maxbutton id="2"]

就像我之前说的,我没有按预期显示按钮,而是看到我在框中输入的内容。

我认为这是由模板解析文本的方式引起的,因为它使用自己的函数(? - php _e('...')) 来回显文本:

<div class="full_content">
<center>
<?php if (squirrel_get_option('squirrel_slidehead') != '') { ?>
<h1><?php echo stripslashes(squirrel_get_option('squirrel_slidehead')); ?></h1>
<?php } else { ?>
<h1><?php _e('We are scope, a design firm in England', 'squirrel'); ?></h1>
<?php } ?>
<?php if (squirrel_get_option('squirrel_slidedesc') != '') { ?>
<h2><?php echo stripslashes(squirrel_get_option('squirrel_slidedesc')); ?></h2>
<?php } else { ?>
<p><?php _e('Newfoundland dogs are good to save children from drowning, but you must have a pond of water handy and a child.', 'squirrel') ?></p>
<p><?php _e('From drowning, but you must have a pond of water handy and a child.', 'squirrel'); ?></p>
<?php } ?>
</center>
</div>

我的问题是,如何让它显示按钮或任何其他代码。

提前致谢。

最佳答案

您可以调用函数 do_shortcode()做正确的shortcode处理一些文本。

例子:

echo do_shortcode('This is a button: [maxbutton id="1"]');

关于php - 如何强制 wordpress 模板解析代码而不是纯文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11741407/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com