Php 自定义帖子类型中的Wordpress列表类别
我有一个查询,下面我只想列出那些分配给我正在查看的当前帖子的类别 目前,它列出了我自定义帖子类型的所有类别。 有没有可能只列出个别职位的职位?文章类型称为“资源”,附加到此文章类型的类别称为“资源类别”Php 自定义帖子类型中的Wordpress列表类别,php,wordpress,custom-post-type,categories,Php,Wordpress,Custom Post Type,Categories,我有一个查询,下面我只想列出那些分配给我正在查看的当前帖子的类别 目前,它列出了我自定义帖子类型的所有类别。 有没有可能只列出个别职位的职位?文章类型称为“资源”,附加到此文章类型的类别称为“资源类别” <?php $taxonomy = 'resource-category'; $tax_terms = get_terms($taxonomy); ?> <?php foreach ($tax_terms as $tax_
<?php
$taxonomy = 'resource-category';
$tax_terms = get_terms($taxonomy);
?>
<?php
foreach ($tax_terms as $tax_term) {
echo '' . '<a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $tax_term->name ) . '" ' . '>' . $tax_term->name.'</a> ';
}
?>
您可以使用:
工作正常,谢谢!
<?php
$taxonomy = 'resource-category';
$tax_terms = wp_get_post_terms($post->ID, $taxonomy, array("fields" => "all"));
foreach ($tax_terms as $tax_term) {
echo '' . '<a href="' . esc_attr(get_term_link($tax_term->term_id, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $tax_term->name ) . '" ' . '>' . $tax_term->name.'</a> ';
}
?>