简体   繁体   中英

How to href a category when click. (wordpress)

I have a wordpress portfolio webpage, and I want to display a categories and I want the categories to be clickable, for example: when I click a category, it will redirect me or link me to that specific category and display all the archives that is related to that category.

how do I insert a href so that when I click a category it will link me to a specific category.

here is my source for the category:

<?php
  foreach((get_the_category()) as $category) {
   echo ' <div class="portfolio__labels "> <p>';
   echo $category->name;
   echo ' </p> </div>';
   }
?>

You can try something like this:

<?php
  foreach((get_the_category()) as $category) {
   echo '<div class="portfolio__labels "> <p>';
   echo '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '">' . $category->name . '</a>';
   //echo $category->name;
   echo '</p> </div>';
   }
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM