Wordpress Category Link get_category_link(id)

2019-07-06 21:05发布

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?

2条回答
趁早两清
2楼-- · 2019-07-06 21:38

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>
查看更多
三岁会撩人
3楼-- · 2019-07-06 21:47

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.

查看更多
登录 后发表回答