Title: Get Category URL
Last modified: August 19, 2016

---

# Get Category URL

 *  Resolved [oldnumber9](https://wordpress.org/support/users/oldnumber9/)
 * (@oldnumber9)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/get-category-url/)
 * I am trying to generate an image link for the category of each post. Here is 
   what I have so far:
 *     ```
       <a href="**NEED CAT URL HERE**">
           <img src="<?php bloginfo('template_url'); ?>/images/<?php foreach((get_the_category()) as $category) {echo $category->cat_name . '-'; } ?>tag.png"></a>
       ```
   
 * As you can see I got the individual pix to load for each category, but I cant
   find a way to load the URL. Any help??
 * Here is the site: [http://www.oldnumbernine.com/mcjh/](http://www.oldnumbernine.com/mcjh/)

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/get-category-url/#post-1126795)
 * The code you have is only going to render one image, do you realise that?
 * You’re outputting a loop of categories inside the src part of the image..
 * So you’ll end up with one image that has a path like…
 * `wp-content/themes/YOURTHEME/images/category1-category2-category3-category-4`
 * and so on….
 * Gimme 5 mins, i’ll write you something… 🙂
 * EDIT::
    Ah, i think i misread slightly, you’re doing this inside the loop for
   each post…
 * I’ll see if i can make you something anyway.. 😉
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/get-category-url/#post-1126798)
 * One quick question, do you expect the result to return more then one category
   or do you want/expect it to return more then one?
 * I’ll post some code in a moment, we can always adjust it if it’s not quite suited
   as is… 🙂
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/get-category-url/#post-1126801)
 * Just wanted to test a few different ideas to get it right, here you go…
 *     ```
       <?php
       $the_cat = get_the_category();
       $category_name = $the_cat[0]->cat_name;
       $category_description = $the_cat[0]->category_description;
       $category_link = get_category_link( $the_cat[0]->cat_ID );
       ?>
   
       <a href="<?php echo $category_link; ?>" class="category_logo">
       <img title="<?php echo $category_description; ?>" src="<?php bloginfo('template_url'); ?>/images/<?php echo $category_name; ?>-tag.png" alt="<?php echo $category_name; ?>" />
       </a>
       ```
   
 * Pretty sure (by looking at your site) you are expecting one category for the 
   result…
 * Hope that helps… 😉
 * NOTE: Added a class to the link so you can style it with the CSS to remove the
   border or anything..
 * Example:
    `.category_logo {}` and `.category_logo img {}`
 *  Thread Starter [oldnumber9](https://wordpress.org/support/users/oldnumber9/)
 * (@oldnumber9)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/get-category-url/#post-1126803)
 * You are right about the loop. What I have now is an icon that changes depending
   on the category the img src returns. There will only be one category assigned
   to each post, so I need the icon to link to that category. Does that make any
   since?
 * Thanks for you help!
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/get-category-url/#post-1126806)
 * Above code will work as is, and will only return the first category…
 * It will link as required to… 🙂
 * Any issues, check the path for the image being generated is correct…
 * I can help further if required.. 😉
 *  Thread Starter [oldnumber9](https://wordpress.org/support/users/oldnumber9/)
 * (@oldnumber9)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/get-category-url/#post-1126807)
 * Success!! Thanks so much for your help!
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/get-category-url/#post-1126808)
 * You’re welcome .. 😉
 * Created just for you.. 😉

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Get Category URL’ is closed to new replies.

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [get](https://wordpress.org/support/topic-tag/get/)
 * [url](https://wordpress.org/support/topic-tag/url/)

 * 7 replies
 * 2 participants
 * Last reply from: [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * Last activity: [16 years, 11 months ago](https://wordpress.org/support/topic/get-category-url/#post-1126808)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
