twentyfifteen_categorized_blog

Determine whether blog/site has more than one category.

Description

twentyfifteen_categorized_blog(); 

Usage

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

Defined (1)

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

/inc/template-tags.php  
  1. function twentyfifteen_categorized_blog() { 
  2. if ( false === ( $all_the_cool_cats = get_transient( 'twentyfifteen_categories' ) ) ) { 
  3. // Create an array of all the categories that are attached to posts. 
  4. $all_the_cool_cats = get_categories( array( 
  5. 'fields' => 'ids',  
  6. 'hide_empty' => 1,  
  7.  
  8. // We only need to know if there is more than one category. 
  9. 'number' => 2,  
  10. ) ); 
  11.  
  12. // Count the number of categories that are attached to the posts. 
  13. $all_the_cool_cats = count( $all_the_cool_cats ); 
  14.  
  15. set_transient( 'twentyfifteen_categories', $all_the_cool_cats ); 
  16.  
  17. if ( $all_the_cool_cats > 1 || is_preview() ) { 
  18. // This blog has more than 1 category so twentyfifteen_categorized_blog should return true. 
  19. return true; 
  20. } else { 
  21. // This blog has only 1 category so twentyfifteen_categorized_blog should return false. 
  22. return false;