最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Link From Single Post To Taxonomy Term Archive Page

programmeradmin1浏览0评论

Need to add a link on all single pages for custom post type taxonomy terms which links back to the taxonomy term archive the single page belongs to.

Using this code but it adds links for all tax terms. I only need the one the single page is assigned to.

$terms = get_terms( array(
    'taxonomy' => 'portfolio',
) );

if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) {

foreach ( $terms as $term ) {

echo '<a href="' . get_term_link( $term->slug, 'portfolio' ) . '">' . $term->name . '</a>';

    }
}

I added this code in the single-portfolio.php file

Need to add a link on all single pages for custom post type taxonomy terms which links back to the taxonomy term archive the single page belongs to.

Using this code but it adds links for all tax terms. I only need the one the single page is assigned to.

$terms = get_terms( array(
    'taxonomy' => 'portfolio',
) );

if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) {

foreach ( $terms as $term ) {

echo '<a href="' . get_term_link( $term->slug, 'portfolio' ) . '">' . $term->name . '</a>';

    }
}

I added this code in the single-portfolio.php file

Share Improve this question edited Sep 23, 2019 at 18:59 Brad Dalton asked Sep 23, 2019 at 18:43 Brad DaltonBrad Dalton 6,9852 gold badges36 silver badges47 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Seems like a good use for get_the_term_list() https://codex.wordpress/Function_Reference/get_the_term_list

发布评论

评论列表(0)

  1. 暂无评论