Link From Single Post To Taxonomy Term Archive Page

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

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745136277a4613215.html

相关推荐

  • Link From Single Post To Taxonomy Term Archive Page

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

    3小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信