我想回复以下代码,但它不起作用:
<?php
if ( is_page('residenz') )
{ echo '[nggallery id=12]'; }
else if ( is_page('apartment-royal-ii') )
{ echo '[nggallery id=13]'; }
else if ( is_page('apartment-royal-iii') )
{ echo '[nggallery id=14]'; }
else if ( is_page('apartment-royal-iv') )
{ echo '[nggallery id=15]'; }
else if ( is_page('apartment-royal-v') )
{ echo '[nggallery id=16]'; }
else { echo '[nggallery id=11]'; }
?>
我认为问题出在方括号中。
我怎样才能回复[nggallery id = 11]?
更多信息:
代码在wordpress小部件中执行。
这就是我修改小部件以接受php的方法:
add_filter('widget_text','execute_php',100);
function execute_php($html){
if(strpos($html,"<"."?php")!==false){
ob_start();
eval("?".">".$html);
$html=ob_get_contents();
ob_end_clean();
}
return $html;
}
EDIT2:
我用过它并且有效:
<?php
if (1 == 1)
{?>
[nggallery id=13]
<?php
}
?>
答案 0 :(得分:3)
使用以下代码回显数据:
<?php
echo htmlentities('[nggallery id=12]');
?>
答案 1 :(得分:1)
方括号不需要转义。我认为你的条件评估为假。 看看以下语句的输出是什么:
var_dump(is_page['residenz'])