【问题标题】:Something like is_term for wordpress conditional tags类似 is_term 的 wordpress 条件标签
【发布时间】:2017-12-11 14:59:48
【问题描述】:

我需要的只是一个函数,它检查的是页面中当前分类法可用的术语。例如,当我想检查我使用的 post_type 中可用的页面时:

<?php if('my_taxonomy' == get_post_type() // DoSomeThing) ?>

现在我想使用这样的东西:

<?php if(is_term_in_current_taxonomy('my_term')) ?>

【问题讨论】:

    标签: wordpress api


    【解决方案1】:

    我想你想要的是这样的,把下面的函数放在function.php中:

    function is_term_in_current_taxonomy($term){
        if($term == get_post_type())
            return true;
        elseif(//some condition)
            return true/false;
        :
    }
    

    【讨论】:

    • 你看,get_post_type() 只是返回帖子类型,我只是想检查当前查看页面的条款是否在当前分类下,例如:我们有一个名为“汽车”的分类' 并且它有 3 个术语,BMWbenzfiat,在某些页面中我们要检查: 1- 如果页面有“汽车”分类? 2-如果当前页面有cars,例如包含BMW?我完全想检查页面中的条款。
    【解决方案2】:

    终于自己找到我想要的了,条件标签是:

    in_array("BMW" , get_terms( 'cars', array('fields'    => 'names'))) AND 'products' == get_post_type()
    

    【讨论】:

      猜你喜欢
      • 2014-04-13
      • 2014-10-18
      • 2012-02-18
      • 1970-01-01
      • 2012-12-12
      • 1970-01-01
      • 2020-08-01
      • 1970-01-01
      • 2014-10-25
      相关资源
      最近更新 更多