Wordpress插件返回网页的PHP
我一直在用WordPress处理一条PHP语句时遇到问题。Wordpress插件返回网页的PHP,php,wordpress,Php,Wordpress,我一直在用WordPress处理一条PHP语句时遇到问题。 基本上,我想要的是: 根据用户选择返回输出 现在我已经设法让我的大部分东西正常工作了,但是当我试图将PHP代码从插件返回到wordpress时,它会立即被注释掉。 这是我正在使用的函数的代码 function display($type, $status) { $html =''; if($type == null) { $html = "<?php echo do_shortcode[contact-form-7 i
基本上,我想要的是:
- 根据用户选择返回输出
这是我正在使用的函数的代码
function display($type, $status) {
$html ='';
if($type == null) {
$html = "<?php echo do_shortcode[contact-form-7 id='7' title='Campaign monitor']');?>";
}else if($type == "ios") {
if ($status == "y")
$html = "IOS";
}else if($type == "android") {
if ($status == "y")
$html = "ANDROID";
}
echo $html;
}
功能显示($type,$status){
$html='';
如果($type==null){
$html="试试这个,因为它有助于减少代码,并使功能更加清晰。它假设如果上面没有列出设备类型,您希望显示默认大小写。它假设如果您的设备没有列出,在这种情况下,除了android和ios之外,它应该显示默认大小写,即您的CF7快捷键de.如果您想指定其他选项,则需要在“默认值”上方完成。如其他地方的注释所述,这是PHP,因此是服务器端处理
<?php
function display($type, $status){
switch ($type){
case "ios":
$html = "IOS";
break;
case "android":
$html = "Android";
break;
default:
$html = "do_shortcode[contact-form-7 id='7' title='Campaign monitor']";
break;
}
if($status == "active"){
echo $html;
}
}
?>
不太确定您想要的效果是什么,但您正在将do_短码中的字符串保存到html中。我假设您将php解析双引号中的变量与正在解析的函数混淆。不是这样。这应该是您想要的
function display($type, $status) {
$html ='';
if($type == null) {
$html = do_shortcode('[contact-form-7 id="7" title="Campaign monitor" ]');
}else if($type == "ios") {
if ($status == "y")
$html = "IOS";
}else if($type == "android") {
if ($status == "y")
$html = "ANDROID";
}
echo $html;
}
这是不可能的。你不能像那样返回PHP代码。PHP代码是服务器端的。你要做的是创建一个字符串。函数显示位于哪个文件中?函数显示位于我的自定义模板PHP文件中。这是你的主题索引.PHP
还是函数.PHP
?这是我的自定义模板mepage这两个都不是。例如,template_homepage.phpIt做的事情与我的代码完全相同,关键是让短代码发挥作用。但它要么显示注释掉的代码,要么像这里一样,是纯字符串。它做的事情是相同的,只是它不包括变量中的开始和结束标记,这是echo服务器应该为您编译的是:echo do_shortcode[contact-form-7 id='7'title='Campaign monitor'];如果不是这样,我也会看看其他方面,看看为什么完美的代码会被修改。你到底是如何调用它的?函数在functions.php中,然后在template_homepage.php中调用?函数位于我的插件文件中,然后显示()在我的模板文件中被调用。正如我所希望的那样工作。非常感谢。
<!--?php echo do_shortcode[contact-form-7 id='7' title='Campaign monitor']');?-->
<?php
function display($type, $status){
switch ($type){
case "ios":
$html = "IOS";
break;
case "android":
$html = "Android";
break;
default:
$html = "do_shortcode[contact-form-7 id='7' title='Campaign monitor']";
break;
}
if($status == "active"){
echo $html;
}
}
?>
function display($type, $status) {
$html ='';
if($type == null) {
$html = do_shortcode('[contact-form-7 id="7" title="Campaign monitor" ]');
}else if($type == "ios") {
if ($status == "y")
$html = "IOS";
}else if($type == "android") {
if ($status == "y")
$html = "ANDROID";
}
echo $html;
}