Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将wordpress短代码更改为数组_Php_Arrays_Wordpress_Shortcode - Fatal编程技术网

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');