WordPress中的语法错误
我正在使用以下代码:WordPress中的语法错误,wordpress,syntax,Wordpress,Syntax,我正在使用以下代码: if (in_category('finance')) { include(TEMPLATEPATH.'/category1.php'); } elseif (in_category('2')) { include(TEMPLATEPATH.'/category2.php'); } else { include(TEMPLATEPATH.'/default.php'); } 一切正常。当我有名为finance的类别时,将使用ca
if (in_category('finance')) {
include(TEMPLATEPATH.'/category1.php');
} elseif (in_category('2')) {
include(TEMPLATEPATH.'/category2.php');
} else {
include(TEMPLATEPATH.'/default.php');
}
一切正常。当我有名为finance的类别时,将使用category1.php中的模板
但现在,我想根据选项请求包括一个特定的模板文件,如下所示:
<?php echo $up_options->category1; ?>
if (in_category('finance')) {
include(TEMPLATEPATH.'/$up_options->category1;');
} elseif (in_category('2')) {
include(TEMPLATEPATH.'/single2.php');
} else {
include(TEMPLATEPATH.'/category1.php');
}
if (in_category('finance')) {
include(TEMPLATEPATH . '/' . $up_options->category1);
}
我在上面的代码中遇到以下错误:
[function.include]: failed to open stream: Invalid argument in.....
非常感谢您的帮助
谢谢。$up\u options是一个变量,但您将其用作字符串。试着这样做:
<?php echo $up_options->category1; ?>
if (in_category('finance')) {
include(TEMPLATEPATH.'/$up_options->category1;');
} elseif (in_category('2')) {
include(TEMPLATEPATH.'/single2.php');
} else {
include(TEMPLATEPATH.'/category1.php');
}
if (in_category('finance')) {
include(TEMPLATEPATH . '/' . $up_options->category1);
}
包括
“/$up\u选项->类别1;”代码>将被解析为字符串
,因为您使用单引号。尝试将其更改为双引号“/$up\u options->category1;”
我认为您不需要添加代码>最后,所以这将更合适
“/$up\u选项->类别1”
第二个选项已由@ninja建议-
TEMPLATEPATH.'/'$向上选项->类别1
谢谢,忍者。不幸的是,您的代码无法工作,同样的错误仍然会发生。@AnabeleRosemaryecho$up\u options->category1代码>?并将完整的错误代码粘贴到名为category1.php和category2.php的模板调用中。这里是错误:“解析错误:语法错误,在第31行的D:\0-SERVER\iwpserver\htdocs\wordpress\wp content\themes\MARIO\category.php中出现意外的T\u编号”@AnabeleRosemaryvar\u dump()
$up\u options->category1;并将结果粘贴到您的问题中作为编辑…然后让我知道您的这次错误似乎与您在post Invalid参数中提到的先前错误不同。。。。