get_the_category_list

本文介绍了WordPress中常用的函数,包括文章查询、用户管理、主题开发等方面的功能。这些函数为开发者提供了强大的工具箱,帮助他们高效地构建和管理网站。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

get_the_category_list






字数4204 · 浏览 · 评论 0

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.

pd.get_dummies is a Python function from the pandas library that is used to create dummy variables from categorical data. It creates a new column for each unique category of a categorical variable, and assigns a value of 1 or 0 to each row depending on whether that row belongs to that category or not. This is useful for machine learning algorithms that require numerical input, as it converts non-numerical data into a numerical format. For example, if we have a dataset with a categorical variable "color" that has three categories: red, green, and blue, pd.get_dummies will create three new columns in the dataset called "color_red", "color_green", and "color_blue". Each row will have a value of 1 in the column that corresponds to its color, and 0 in the other two columns. The syntax for pd.get_dummies is: ``` pd.get_dummies(data, columns=None, prefix=None, prefix_sep='_', dummy_na=False, drop_first=False) ``` - data: the input pandas DataFrame or Series - columns: the name or list of names of the columns to encode. If not specified, all non-numerical columns will be encoded. - prefix: the prefix to add to the column names of the new dummy variables - prefix_sep: the separator to use between the prefix and the original column name - dummy_na: whether to create an additional column for missing values. If True, a column called "column_name_nan" will be created for each column with missing values. - drop_first: whether to drop the first column of each set of dummy variables to avoid multicollinearity. If True, the first column will be dropped.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值