Wordpress 类别链接 get_category_link(id)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2273529/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 18:34:26  来源:igfitidea点击:

Wordpress Category Link get_category_link(id)

wordpresscategoriespermalinks

提问by Matrym

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

我需要链接到我的 wordpress 网站中的一个类别。以下代码在某种程度上有效:

                <?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?

我的问题是它在 url 中包含 /category/,这不是我的永久链接结构的设计方式。有没有人知道在它输出的 url 中包含 /category/ 的方法?

采纳答案by markratledge

I don't understand what you want to do. Look here Template Tags/wp list categories ? WordPress Codexfor 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:

我不明白你想做什么。看这里模板标签/wp 列表类别?WordPress Codex用于类别菜单的模板标签,将包括您设置的任何类别基础。如果要在类别页面本身上输出指向类别的链接,请使用:

<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>

回答by Matrym

I found a plugin that does work with 2.9:

我找到了一个适用于 2.9 的插件:

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

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.

不过,对于那些可能知道如何在没有插件的情况下解决问题的人,我将把这个问题保持开放。