0

我希望你给我一个实际的答案(对你来说可能是简单的问题)。我已经创建了一个名为(示例:)“Cuspost”的自定义帖子类型,并且我在Cuspost内部具有名为“Custax”的自定义分类标准。然后我有分类法:Custax中的“Custax”和“B Custax”。自定义帖子类型中的自定义分类标准的条件标签

我想要做的只是想检查Custax的值,例如has_custax('a-custax')(类似于has_category('a-category'));

下使用是这样的:

<?php if (has_custax('a-custax')) { 
    echo 'do something A'; 
} else { 
    echo 'do something B'; 
} 

供您参考,我读过这个(http://wordpress.org/support/topic/custom-taxonomies-conditional-tags#post-1110167)和它不是工作。

感谢您的帮助。

回答

0

使用此功能解决对functions.php类似贾斯汀Tadlock解决方案

<?php function has_custax($custax, $_post = null) { 
    if (empty($custax)) 
     return false; 
    if ($_post) 
     $_post = get_post($_post); 
    else 
     $_post =& $GLOBALS['post']; 
    if (!$_post) 
     return false; 
    $r = is_object_in_term($_post->ID, 'custax', $custax); 
    if (is_wp_error($r)) 
     return false; 
    return $r; 
} 
?> 

这是有条件的标签。可以在/使用外循环:

<?php if (has_custax('a-custax', $post->ID)) { 
     echo 'do something A'; 
} else { echo 'do something B'; }; ?> 

感谢我的朋友Sulton Hasanudin

相关问题