get_the_category_list()获取所有分类,并以html的形式显示

目录

描述

Retrieve category list in either HTML list or custom format. Generally used for quick, delimited (eg: comma-separated) lists of categories, as part of a post's entry meta. For a more powerful, list-based function, see wp_list_categories().

get_the_category_list() 描述

用法

<?php get_the_category_list$separator$parents$post_id ); ?>

get_the_category_list() 用法

参数

$separator

(string) (可选) Optional, default is empty string. Separator for between the categories.

默认值: empty string

$parents

(string) (可选) Optional. How to display the parents. Values: 'multiple', 'single', empty string

默认值: empty string

$post_id

(int) (可选) Optional. Post ID to retrieve categories.

默认值: false

get_the_category_list() 参数

返回值

(string

get_the_category_list() 返回值

示例

Implementation in WordPress default Twenty Eleven theme

In content-single.php:

Display as List Items

By leaving the $separator value empty, it will generate an unordered list instead, complete with classes.

Result:

get_the_category_list() 示例

注意

Categories are ordered by name regardless of the parent-child category relationship. See this example from wp_list_categories() to display the Post categories with the category relationship intact.

get_the_category_list() 注意

历史

添加于 版本: 1.5.1

get_the_category_list() 历史

源文件

get_the_category_list() 函数的代码位于 wp-includes/category-template.php

get_the_category_list() 源文件

相关