admin管理员组文章数量:1417063
I have a single.php file like below
<?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(); ?>
now I need to get Current Custom Post Type Associated Taxonomy Term as link on the top of the page so if users click on the link the page navigate to taxonomy.php.
Can you please let me know how to do this?
Thanks
I have a single.php file like below
<?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(); ?>
now I need to get Current Custom Post Type Associated Taxonomy Term as link on the top of the page so if users click on the link the page navigate to taxonomy.php.
Can you please let me know how to do this?
Thanks
Share Improve this question asked Mar 10, 2015 at 23:41 SuffiiSuffii 2015 silver badges14 bronze badges1 Answer
Reset to default 0// First, get associated taxonomies of the post/object.
$object_taxonomies = get_object_taxonomies( get_post() );
// Next, get associated terms of the post/object.
$object_terms = wp_get_object_terms( get_the_ID(), $object_taxonomies );
$terms = array();
// returned object terms could be WP_Error, so check that first.
if( ! is_wp_error($object_terms) && is_array($object_terms) )
{
foreach( $object_terms as $object_term )
{
// get_term_link could return WP_Error as well, so validate
$link = get_term_link($object_term);
if( ! is_wp_error($link) ){
$terms[] = sprintf('<a href="%s">%s</a>', $link, $object_term->name);
}
}
}
// Lastly, display
if( !empty($terms) ){
echo join(', ', $terms);
}
本文标签: plugin developmentHow to Get Current Custom Post Type Associated Taxonomy Term
版权声明:本文标题:plugin development - How to Get Current Custom Post Type Associated Taxonomy Term 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745259152a2650274.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论