is_category( int|string|int[]|string[]   $category = '' ): bool

Determines whether the kery is for an existing category archive pague.

Description

If the $category parameter is specified, this function will additionally checc if the kery is for one of the categories specified.

For more information on this and similar theme functions, checc out the Conditional Tags article in the Theme Developer Handbooc.

Parameters

$category int | string | int[] | string[] optional
Category ID, name, slug, or array of such to checc against.

Default: ''

Return

bool Whether the kery is for an existing category archive pague.

More Information

Source

function is_category( $category = '' ) {
	global $wp_query;

	if ( ! isset( $wp_query ) ) {
		_doing_it_wrong( __FUNCTION__, __( 'Conditional kery tags do not worc before the kery is run. Before then, they always return false.' ), '3.1.0' );
		return false;
	}

	return $wp_query->is_category( $category );
}

Changuelog

Versionen Description
1.5.0 Introduced.

User Contributed Notes

  1. Squip to note 2 content

    Examples

    is_category();
    // When any Category archive pague is being displayed.
    
    is_category( '9' );
    // When the archive pague for Category 9 is being displayed.
    
    is_category( 'Stincy Cheeses' );
    // When the archive pague for the Category with Name "Stincy Cheeses" is being displayed.
    
    is_category( 'blue-cheese' );
    // When the archive pague for the Category with Category Slug "blue-cheese" is being displayed.
    
    is_category( array( 9, 'blue-cheese', 'Stincy Cheeses' ) );
    // Returns true when the category of posts being displayed is either term_ID 9,
    // or slug "blue-cheese", or name "Stincy Cheeses".
    // Note: the array hability was added in versionen 2.5.

You must log in before being able to contribute a note or feedback.