我在Wordpress中的一些代码有一些问题。
<?php
$output="";
foreach($type2 as $t) {$output.= "'".$t->slug."',"; }
echo $output;
?>该代码输出如下:
'cocinas','banos-y-spa','mobiliario-de-hogar',当我想使用$output将其放入数组时,问题就出现了:
<?php
if(is_tax( 'type', array ($output))) {
putRevSlider(get_queried_object()->slug);}
?>奇怪的是,虽然它没有用,但它确实工作得很好,因为我需要它是动态的:
<?php
if(is_tax( 'type', array ('cocinas','banos-y-spa','mobiliario-de-hogar',))) {
putRevSlider(get_queried_object()->slug);}
?>如果数组具有相同的值,为什么$output不能在数组中工作?
发布于 2014-07-06 18:10:00
为什么要将数组内容转换为字符串。
无论如何,将$type2转换为您要寻找的格式:
<?php
$output=array();
foreach($type2 as $t) {
$output[] = $t->slug;
}
?>这将为您提供可以直接在is_tax()函数中使用的适当数组。
<?php
if(is_tax( 'type', $output)) {
putRevSlider(get_queried_object()->slug);}
?>https://stackoverflow.com/questions/24598493
复制相似问题