get_category_link()通过分类id获取分类的网址链接

目录

描述

译文

检索类别的链接URL。

原文

Returns the correct url for a given Category ID.

In a Plugin or Theme, it can be used as early as the setup_theme Action. Any earlier usage, including plugins_loaded, generates a Fatal Error.

get_category_link() 描述

用法

<?php get_category_link$category_id ); ?> 

get_category_link() 用法

参数

$category_id

(integer) (必填) The category ID whose link will be retrieved.

默认值: None

get_category_link() 参数

返回值

(URL) 

(string) URL with a link to the category.

get_category_link() 返回值

示例

Category Link

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
<?php
    // Get the ID of a given category
    $category_id = get_cat_ID( 'Category Name' );

    // Get the URL of this category
    $category_link = get_category_link( $category_id );
?>

<!-- Print a link to this category -->
<a href="<?php echo esc_url( $category_link ); ?>" title="Category Name">Category Name</a>

get_category_link() 示例

注意

get_category_link() 注意

历史

添加于 版本: 1.0.0

get_category_link() 历史

源文件

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

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Retrieve category link URL.
 *
 * @since 1.0.0
 * @see get_term_link()
 *
 * @param int|object $category Category ID or object.
 * @return string Link on success, empty string if category does not exist.
 */
function get_category_link( $category ) {
	if ( ! is_object( $category ) )
		$category = (int) $category;

	$category = get_term_link( $category, 'category' );

	if ( is_wp_error( $category ) )
		return '';

	return $category;
}

get_category_link() 源文件

相关