doudou6719 2017-10-25 03:32
浏览 72

如何将wordpress短代码更改为数组

I get a syntax error when I add an array. Will someone point out where I have made a mistake?

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');
  • 写回答

3条回答 默认 最新

  • douqian9729 2017-10-25 03:39
    关注

    forgot to open a php tag before ob_start, forgot the dollar sign($) when declaring the has_term variable and forgot to close the php tag at the end of the code.

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

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料