Support » Themes and Templates » link to category inside post?

  • hey guys, i simply want to have a link to the category my current post fits in.

    currently I’m using:

    <?php
    			$category = get_the_category();
    			echo "<span class='catname'>" . $category[0]->cat_name . "</span>";
    			?>

    however, this is just the name of the category. i need a link to the category archive.

    is there a template_tag to use?
    thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Yea you can use this:

    <?php
        // Get the ID of a given category
        $category = get_the_category();
        $category_id = $category[0]->cat_ID;
        $category_name = $category[0]->cat_name; 
    
        // Get the URL of this category
        $category_link = get_category_link( $category_id );
    ?>
    
    <!-- Print a link to this category -->
    <a href="<?php echo $category_link; ?>" title="Category Name"><?php echo $category_name; ?></a>

    thank you, worked perfectly!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘link to category inside post?’ is closed to new replies.