get_category_link() 不返回任何内容
我正在使用 get_categories() 函数为自己手动创建一个导航菜单。我正在使用一个名为 Category 的自定义分类法,并且我尝试使用 get_category_link() 函数返回菜单中标签的链接。
foreach ($categories as $category) {
if ($category->parent == 0) { //Check to see it is a parent
$output .= '<li>';
$output .= '<a href="' . get_category_link($category->cat_ID) . '">' . $category->name . '</a>'; //display parent taxonomy category
}
}
但它总是返回 。我可以成功回显
$category->cat_ID
,因此我知道它将 ID 传递到函数中,但我不知道为什么它返回空白。
我错过了什么吗?是因为这些是自定义分类法吗?他们有蛞蝓。
I am using the get_categories() function to manually create myself a nav menu. I have a custom taxonomy I'm using called Category and I'm trying to return the link for it for my tags in the menu using the get_category_link() function.
foreach ($categories as $category) {
if ($category->parent == 0) { //Check to see it is a parent
$output .= '<li>';
$output .= '<a href="' . get_category_link($category->cat_ID) . '">' . $category->name . '</a>'; //display parent taxonomy category
}
}
But it always returns <a href="">
. I can echo out the $category->cat_ID
successfully so I know it is passing the ID into the function but I don't know why it's returning blank.
Am I missing something? Is it because these are custom taxonomies? They have slugs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于自定义分类法,您需要类似的内容:
尽管您可以轻松添加到脚本顶部以获取要输入的所有分类法的数组(如果您愿意)。
You need something like this for custom taxonomies:
Although you can easily add to the top of the script to get an array of all taxonomies to feed in if you wanted.