【发布时间】: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')) ?>
【问题讨论】:
我需要的只是一个函数,它检查的是页面中当前分类法可用的术语。例如,当我想检查我使用的 post_type 中可用的页面时:
<?php if('my_taxonomy' == get_post_type() // DoSomeThing) ?>
现在我想使用这样的东西:
<?php if(is_term_in_current_taxonomy('my_term')) ?>
【问题讨论】:
我想你想要的是这样的,把下面的函数放在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 个术语,BMW,benz,fiat,在某些页面中我们要检查: 1- 如果页面有“汽车”分类? 2-如果当前页面有cars,例如包含BMW?我完全想检查页面中的条款。
终于自己找到我想要的了,条件标签是:
in_array("BMW" , get_terms( 'cars', array('fields' => 'names'))) AND 'products' == get_post_type()
【讨论】: