get_category_link()

最后更新于:2021-11-26 07:16:20

get_category_link( int|object$category)

Retrieves category link URL.

参数

$category

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

响应

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

源文件

文件: gc-includes/category-template.php

function get_category_link( $category ) {
	if ( ! is_object( $category ) ) {
		$category = (int) $category;
	}

	$category = get_term_link( $category );

	if ( is_gc_error( $category ) ) {
		return '';
	}

	return $category;
}
<div class="card border border-0 m-2" style="width: 250px;">

    <div class="card-header bg-primary text-white">
        <h5>Categorias</h5>
    </div>

    <?php
    foreach ( $categories as $category ) {
        echo '<a class="text-decoration-none list-group-item list-group-item-action text-dark" href="' . esc_attr( esc_url( get_category_link( $category->term_id ) ) ) . '">;
        echo '<div class="d-flex justify-content-between align-items-start">';
        echo esc_html( $category->name );
        echo '<span class="badge bg-primary rounded-pill">' . esc_html( $category->count ) . '</span>';
        echo '</div>';
        echo '</a>';
    }
    ?>

</div>