views:

798

answers:

2

I need to link to a category in my wordpress site. The following code works, somewhat:

                <?php
 // Get the ID of a given category
 $category_id = get_cat_ID( 'People' );

 // Get the URL of this category
 $category_link = get_category_link( $category_id );
    ?>

My problem is that it includes /category/ in the url, which isn't how my permalink structure is designed. Does anyone know a way around including /category/ in the url it outputs?

A: 

I found a plugin that does work with 2.9:

http://wordpress.org/extend/plugins/wp-no-category-base/

I'm going to leave the question open, though, for those who may know how to solve the problem without a plugin.

Matrym
A: 

I don't understand what you want to do. Look here Template Tags/wp list categories « WordPress Codex for the template tag for category menus that will include whatever category base you have set. If you want to output the link to a category on the category page itself, then use:

<a href="<?php bloginfo('url'); ?>/<?php $category = get_the_category(); echo $category[0]->category_nicename; ?>" title="<?php echo $category[0]->category_nicename; ?>">

<?php $category = get_the_category(); echo $category[0]->category_description; ?></a>
songdogtech
Was brain dead and didn't consider that solution. There is a built in "link to category" tag, but it automatically prepends the link with garbage. Thx!
Matrym
I should note that if the permalink structure changes, then these urls will break. Using the category link tag, it will maintain linkage.
Matrym
Right; the wordpress functions will regardless of permalink settings and with the plugin no-category-base, too...
songdogtech