
此短代码可在您的 WordPress 网站上显示包含帖子数量的类别列表。
PHP 代码:
// 显示 WordPress 类别及其帖子数量
function display_categories_with_post_count() {
$categories = get_categories();
$output = '- ';
foreach ($categories as $category) {
$output .= '
- ' . $category->name . ' (' . $category->count . ') '; } $output .= '
CSS 代码:
/* 样式设置:WordPress 类别列表 */
.sf-categories {
display: flex;
flex-direction: column;
gap: 8px;
list-style: none;
margin: 0;
padding: 0;
}
.sf-categories li a {
display: flex;
background-color: #fff;
color: #000;
border-radius: 8px;
padding: 10px 16px;
font-size: 1rem;
text-decoration: none;
transition: all .2s ease-in-out;
}
.sf-categories li a span {
display: block;
position: absolute;
right: 16px;
top: 50%;
transform: translateY(-50%);
padding: 3px 8px;
font-size: 0.85rem;
line-height: 1;
background-color: rgba(0, 0, 0, 0.05);
border-radius: 4px;
}
.sf-categories li a:hover {
background-color: #46A787;
color: #fff;
}
.sf-categories li a:hover span {
background-color: rgba(255, 255, 255, 0.1);
color: #fff;
}
完整文章:WordPress 类别列表及其帖子数量
完全公开源代码,并无任何许可限制 特别基于大型电子商务网站的系统开发 Microsoft SQL Server 2000后台数据库,充分应用了存储过程的巨大功效 基于类模块的扩展数据访问能力支持任何类型的大型数据库 加密用户登录信息(cookie) 易于安装的系统和应用功能 100%的asp.net的代码,没有COM,java或者其他的格式 完全基于MS建议的系统安全设计 最佳的应用程序,数据库









