Wordpress Category Link get_category_link(id)

放肆的年华 提交于 2019-12-10 21:50:17

问题


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?


回答1:


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>



回答2:


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.



来源:https://stackoverflow.com/questions/2273529/wordpress-category-link-get-category-linkid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!