get_category_template

Retrieve path of category template in current or parent template.

Description

(string) get_category_template(); 

The hierarchy for this template looks like:

1. category-.php 2. category-.php 3. category.php

An example of this is:

1. category-news.php 2. category-2.php 3. category.php

The template hierarchy is filterable via the hook. The template path is filterable via the hook.

Returns (string)

Full path to category template file.


Usage

  1. if ( !function_exists( 'get_category_template' ) ) { 
  2. require_once ABSPATH . WPINC . '/template.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = get_category_template(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/template.php  
  1. function get_category_template() { 
  2. $category = get_queried_object(); 
  3.  
  4. $templates = array(); 
  5.  
  6. if ( ! empty( $category->slug ) ) { 
  7.  
  8. $slug_decoded = urldecode( $category->slug ); 
  9. if ( $slug_decoded !== $category->slug ) { 
  10. $templates[] = "category-{$slug_decoded}.php"; 
  11.  
  12. $templates[] = "category-{$category->slug}.php"; 
  13. $templates[] = "category-{$category->term_id}.php"; 
  14. $templates[] = 'category.php'; 
  15.  
  16. return get_query_template( 'category', $templates );