get_the_category_list
来源:互联网 发布:四川厚名网络 编辑:程序博客网 时间:2024/06/05 15:17
get_the_category_list
Description
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().
Usage
<?php get_the_category_list( $separator, $parents, $post_id ); ?>
Parameters
$separator
- (string) (optional) Optional, default is empty string. Separator for between the categories.
- Default: empty string
$parents
- (string) (optional) Optional. How to display the parents. Values: ‘multiple’, ‘single’, empty string
- Default: empty string
$post_id
- (int) (optional) Optional. Post ID to retrieve categories.
- Default: false
Return Values
(string)
Notes
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.
Examples
Implementation in WordPress default Twenty Eleven theme
In content-single.php:
<?php/* translators: used between list items, there is a space after the comma */$categories_list = get_the_category_list( __( ', ', 'twentyeleven' ) );/* translators: used between list items, there is a space after the comma */$tag_list = get_the_tag_list( '', __( ', ', 'twentyeleven' ) );if ( '' != $tag_list ) {$utility_text = __( 'This entry was posted in %1$s and tagged %2$s by <a href="%6$s">%5$s</a>. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyeleven' );} elseif ( '' != $categories_list ) {$utility_text = __( 'This entry was posted in %1$s by <a href="%6$s">%5$s</a>. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyeleven' );} else {$utility_text = __( 'This entry was posted by <a href="%6$s">%5$s</a>. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyeleven' );}printf($utility_text,$categories_list,$tag_list,esc_url( get_permalink() ),the_title_attribute( 'echo=0' ),get_the_author(),esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ));?>
Display as List Items
By leaving the $separator value empty, it will generate an unordered list instead, complete with classes.
<?php echo get_the_category_list(); ?>
Result:
<ul class="post-categories"><li><a href="http://myblog.com/category/business" title="View all posts in Business" rel="category tag">Business</a></li></ul>
Change Log
Since: 1.5.1
Source File
get_the_category_list()
is located in wp-includes/category-template.php
Related
- Article: Categories
- Function: the_category()
- Function: the_category_rss()
- Function: single_cat_title()
- Function: category_description()
- Function: wp_dropdown_categories()
- Function: wp_list_categories()
- Function: get_the_category()
- Function: get_the_category_by_ID()
- Function: get_category_by_slug()
- Function: get_the_category_list()
- Function: get_category_parents()
- Function: get_category_link()
- Function: is_category()
- Function: in_category()
See also index of Function Reference and index of Template Tags.
- get_the_category_list
- WordPress分类页面获取当前分类的ID
- 自然语言查询接口IDCQ(二)算法描述
- 内存
- ROS gazebo激光传感器扫描存在部分扫描没有值问题
- HDU2102-A计划
- get_the_category_list
- CSDN日报20170222——《未来最重要的三个能力》
- **JAVA** GUI图形界面编程-swing的使用
- 最近找java实习面试被问到的东西总结(Java方向)
- raw h264怎么判断是否有丢包?
- Unity3D之编辑器脚本获取资源内存和硬盘大小
- H5图片展示
- 基本元器件之贴片电阻封装尺寸功率表
- C++ http 流媒体等 开源项目记录