Php wordpress,获取自定义帖子类型的类别名称
有没有更好的方法在wordpress中获取自定义帖子类型的类别名称Php wordpress,获取自定义帖子类型的类别名称,php,html,css,wordpress,Php,Html,Css,Wordpress,有没有更好的方法在wordpress中获取自定义帖子类型的类别名称 <?php // get the portfolio categories $terms = get_the_terms( $post->ID, 'filters' ); if ( $terms && ! is_wp_error( $terms ) ) :
<?php // get the portfolio categories
$terms = get_the_terms( $post->ID, 'filters' );
if ( $terms && ! is_wp_error( $terms ) ) :
$names = array();
$slugs = array();
foreach ( $terms as $term ) {
$names[] = $term->name;
$slugs[] = $term->slug;
}
$name_list = join( " / ", $names );
$slug_list = join( " category-", $slugs );
endif;
?>
<!-- BEGIN portfolio-item-->
<li class="portfolio-item third column category-<?php echo $slug_list; ?>" data-filter="category-<?php echo $slug_list; ?>">
并将函数调用为:
<?php $cat = get_the_category_custompost($post->ID, 'Your Custom Taxonomy'); ?>
我的答案似乎太简单了,但我用它列出了wordpress插件中的类别,该插件名为,与标准wp类别有单独的类别
我假设Design Wall使用自定义帖子类型来创建q&a部分,并使用分类法来创建类别
<ul>
<?php wp_list_categories('taxonomy=dwqa-question_category&hide_empty=0&orderby=id&title_li=');?>
</ul>
假设您的自定义分类法是recipegroups,我已经在functions.php中实现并测试了这段代码,我相信它也可以在插件中使用
$recipeTerms = get_terms(array(
'taxonomy' => 'recipegroups',
));
foreach($recipeTerms as $recipeTerm){
if($recipeTerm->parent==0){
echo "<div class='termsBox'>"; // remove these div's to suit your needs..
$termLink =get_term_link( $recipeTerm );
echo "<a href='$termLink'><div class='termParent'>".$recipeTerm->name."</div></a> ";
$termChilds = get_term_children($recipeTerm->term_id, 'recipegroups' );
foreach($termChilds as $child){
$chTerm = get_term_by( 'id', $child, 'recipegroups');
$termLink =get_term_link( $chTerm );
echo "<a href='$termLink'><div class='top-cat-items'>".$chTerm->name."</div></a>";
}
echo "</div>"; // end of termsBox div
}
}
$recipeTerms=获取术语(数组(
“分类法”=>“RecipeGroup”,
));
foreach($recipeTerm作为$recipeTerm){
如果($recipeTerm->parent==0){
echo”“;//删除这些div以满足您的需要。。
$termLink=获取术语链接($recipeTerm);
回声“;
$termChilds=get_term_childs($recipeTerm->term_id,'RecipeGroup');
foreach($termChilds as$child){
$chTerm=get_term_by('id',$child,'recipegroups');
$termLink=获取术语链接($chTerm);
回声“;
}
echo“”;//终端盒div的结尾
}
}
谢谢您的帮助;非常感谢
<ul>
<?php wp_list_categories('taxonomy=dwqa-question_category&hide_empty=0&orderby=id&title_li=');?>
</ul>
$recipeTerms = get_terms(array(
'taxonomy' => 'recipegroups',
));
foreach($recipeTerms as $recipeTerm){
if($recipeTerm->parent==0){
echo "<div class='termsBox'>"; // remove these div's to suit your needs..
$termLink =get_term_link( $recipeTerm );
echo "<a href='$termLink'><div class='termParent'>".$recipeTerm->name."</div></a> ";
$termChilds = get_term_children($recipeTerm->term_id, 'recipegroups' );
foreach($termChilds as $child){
$chTerm = get_term_by( 'id', $child, 'recipegroups');
$termLink =get_term_link( $chTerm );
echo "<a href='$termLink'><div class='top-cat-items'>".$chTerm->name."</div></a>";
}
echo "</div>"; // end of termsBox div
}
}