get_category_link() - WordPress 函数参考中文文档

返回介绍

get_category_link()

发布于 2017-09-10 字数2177 浏览 820 评论 0

get_category_link( int|object $category )

Retrieve category link URL.


描述


参数

$category

(int|object)
(Required)
Category ID or object.


返回值

(string) Link on success, empty string if category does not exist.


源代码

File: wp-includes/category-template.php

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;
}

更新日志

Version 描述
1.0.0 Introduced.

相关函数

Uses

  • wp-includes/taxonomy.php:
    get_term_link()
  • wp-includes/load.php:
    is_wp_error()

Used By

  • wp-includes/category-template.php:
    get_the_category_list()
  • wp-includes/class-wp-xmlrpc-server.php:
    wp_xmlrpc_server::mw_getCategories()

User Contributed Notes

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Category Link

    
    <?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>
    
    

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!