customization - How do I list custom taxonomy terms with the links?

admin2025-04-20  0

I've the following code which gives the list of the portfolio category as text. What can I do to have them as links instead? thank you

  function thb_display_category_cus() {
  if ('portfolio' === get_post_type() ) {
    $categories = get_the_term_list( get_the_ID(), 'portfolio-category', '', ', ', '' );
    if ($categories !== '' && !empty($categories) ) {
        $categories = strip_tags($categories);
    }


 echo 

    esc_html($categories); 


      } else {
        the_category(', ' );
      }
    }

I've the following code which gives the list of the portfolio category as text. What can I do to have them as links instead? thank you

  function thb_display_category_cus() {
  if ('portfolio' === get_post_type() ) {
    $categories = get_the_term_list( get_the_ID(), 'portfolio-category', '', ', ', '' );
    if ($categories !== '' && !empty($categories) ) {
        $categories = strip_tags($categories);
    }


 echo 

    esc_html($categories); 


      } else {
        the_category(', ' );
      }
    }
Share Improve this question asked Sep 30, 2019 at 21:55 DandeDande 351 silver badge8 bronze badges 2
  • Take out your second "if" statement - the strip_tags() function is removing the links. – WebElaine Commented Sep 30, 2019 at 22:00
  • thanks. ok now I've that as result <a href="https://yoursite/portfolio-category/test/" rel="tag">test</a> (as pure text). How can I transform this in a hyperlink? – Dande Commented Sep 30, 2019 at 22:41
Add a comment  | 

1 Answer 1

Reset to default 1

WebElain was correct but, you've also got the HTML escaped. The entire chunk of code should be:

  function thb_display_category_cus() {
  if ('portfolio' === get_post_type() ) {
    $categories = get_the_term_list( get_the_ID(), 'portfolio-category', '', ', ', '' );



 echo $categories


      } else {
        the_category(', ' );
      }
    }
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745116917a285917.html

最新回复(0)