WordPress的类别链接get_category_link(id) [英] Wordpress Category Link get_category_link(id)

查看:63
本文介绍了WordPress的类别链接get_category_link(id)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要链接到我的wordpress网站中的类别.以下代码可以正常工作:

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

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

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?

推荐答案

我不明白您想做什么.在此处模板标签/wp列表类别«WordPress Codex 可获得类别菜单的模板标签包括您设置的任何类别库.如果要在类别页面本身上输出到类别的链接,请使用:

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>

这篇关于WordPress的类别链接get_category_link(id)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆