Php 如何将wordpress短代码更改为数组
我在添加数组时出现语法错误。有人能指出我在哪里犯了错误吗Php 如何将wordpress短代码更改为数组,php,arrays,wordpress,shortcode,Php,Arrays,Wordpress,Shortcode,我在添加数组时出现语法错误。有人能指出我在哪里犯了错误吗 function commresi() { ob_start(); ?> <?php if( has_term=array('commercial',’commercial-filtration’,'commercial-water-softeners’,’category') ) { ?> <p class="commercia
function commresi() {
ob_start();
?>
<?php if( has_term=array('commercial',’commercial-filtration’,'commercial-water-softeners’,’category') ) { ?>
<p class="commercial com-res"><a href="/home">Visit Residential Systems</a></p>
<?php } else { ?>
<p class="not-commercial com-res"><a href="/commercial">Visit Commercial Systems</a></p>
<?php } ?>
<?php
return ob_get_clean();
}
add_shortcode('comres', 'commresi');
在ob_开始之前忘记打开php标记,在声明has_term变量时忘记美元符号$,在代码末尾忘记关闭php标记
function commresi()
{
<?php
ob_start();
?>
<?php
if ($has_term = array(
'commercial',
’commercial - filtration’,
'commercial-water-softeners’,’category'
))
{ ?>
<p class="commercial com-res"><a href="/home">Visit Residential Systems</a></p>
<?php
}
else
{ ?>
<p class="not-commercial com-res"><a href="/commercial">Visit Commercial Systems</a></p>
<?php
} ?>
<?php
return ob_get_clean();
?>
}
add_shortcode('comres', 'commresi');
忘记了$sign之前有\u术语变量
使用此代码:
function commresi() {
$commercial_array = array('commercial','commercial-filtration','commercial-water-softeners','category');
$return = ' <p class="not-commercial com-res"><a href="/commercial">Visit Commercial Systems</a></p>';
if( in_array ($has_term, $commercial_array) ) {
$return = ' <p class="commercial com-res"><a href="/home">Visit Residential Systems</a></p>';
}
return $return;
}
add_shortcode('comres', 'commresi');
其中,$has_term是要从$commercial_数组中匹配的术语
function commresi() {
$commercial_array = array('commercial','commercial-filtration','commercial-water-softeners','category');
$return = ' <p class="not-commercial com-res"><a href="/commercial">Visit Commercial Systems</a></p>';
if( in_array ($has_term, $commercial_array) ) {
$return = ' <p class="commercial com-res"><a href="/home">Visit Residential Systems</a></p>';
}
return $return;
}
add_shortcode('comres', 'commresi');