如何获取当前海关邮政类型关联分类术语

时间:2015-03-10 作者:Suffii

我有一张单人床。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(); ?>
现在,我需要在页面顶部以链接的形式获取当前自定义贴子类型关联的分类术语,以便如果用户单击该链接,页面将导航到分类。php。

你能告诉我怎么做吗?

谢谢

1 个回复
SO网友:Shazzad
// 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);
}
结束