How to lynch a post categories on a Wordpress site

Asked

Viewed 29 times

0

I have a website on Wordpress. I want to display the categories on post, I mean, my theme. I tried the code below, but only the name of the categories of the post appears, but only text, there is no way to click and go in the category.. Can help me ?

My Code:

<div>
<?php 
    foreach((get_the_category()) as $category){
        echo $category->name."<br>";
        echo category_description($category);
        }
    ?>
</div>

1 answer

2


Turns out you’re not creating the element anchovy (or <a>).

The correct is:

<div>
<?php 
    foreach(get_the_category() as $category){
        echo "<a href=\"".get_category_link($category->term_id)."\">{$category->name}</a><br>";
        echo category_description($category);
    }
?>
</div>
  • Great, you helped me a lot!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.