如何获取当前自定义 Post 类型关联的分类术语
How to Get Current Custom Post Type Associated Taxonomy Term
我有一个 single.php 文件,如下所示
<?php get_header(); ?>
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
echo '<div">';
the_content();
echo '</div>';
} // end while
} // end if
?>
<?php get_footer(); ?>
现在我需要在页面顶部获取 Current Custom Post Type Associated Taxonomy Term as link 这样如果用户单击 link 页面导航到 taxonomy.php.
你能告诉我怎么做吗?
谢谢
您可以在循环中使用 get_the_term_list 来获取相关的分类术语链接:
global $post
$terms = get_the_term_list($post->ID, 'your_taxonomy');
echo $terms;
这对我来说是一个很好的解决方案,因为我只有一个分类术语与每个 post 相关联。
我有一个 single.php 文件,如下所示
<?php get_header(); ?>
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
echo '<div">';
the_content();
echo '</div>';
} // end while
} // end if
?>
<?php get_footer(); ?>
现在我需要在页面顶部获取 Current Custom Post Type Associated Taxonomy Term as link 这样如果用户单击 link 页面导航到 taxonomy.php.
你能告诉我怎么做吗?
谢谢
您可以在循环中使用 get_the_term_list 来获取相关的分类术语链接:
global $post
$terms = get_the_term_list($post->ID, 'your_taxonomy');
echo $terms;
这对我来说是一个很好的解决方案,因为我只有一个分类术语与每个 post 相关联。