wordpress - Empty categories are not listed - wordpress
问题描述
I want to show empty categories in the list.What is wrong with this code?
function cat_list(){
$args = array(
'hide_empty' => 0,
'orderby' => "name",
'order' => "ASC" );
$categories = get_categories(args);
foreach($categories as $category){
echo '<li><a href="' .get_category_link($category->term_id) . '"> '. $category->name . '</a></li>';
}
}
解决方案
You have a missing $
while passing arguments to get_categories
. Here's the fixed one.
function cat_list(){
$args = array(
'hide_empty' => 0,
'orderby' => "name",
'order' => "ASC" );
$categories = get_categories($args);
foreach($categories as $category){
echo '<li><a href="' .get_category_link($category->term_id) . '"> '. $category->name . '</a></li>';
}
推荐阅读
- go - 并行循环
- javascript - javascript在不使用内联函数的情况下动态添加类
- angular - 如何在 Angular 6 中切换输入?
- git - 上游 git 标签未显示在分叉的存储库中
- mongodb - Ubuntu 18.04 中的 MongoDB Zip 安装失败
- python - 如何使用 Flask 应用程序和 BaleBot 向用户发送消息
- java - 了解正则表达式以从字符串中删除 HTML 标记
- python - 我应该如何使以下打印语句为一行的每个部分占用一致的空格数?
- php - 定义一个类来调用它的函数,但它无法识别并显示错误
- grpc - 使用 gevent 和 grpc 缩放问题