| | 336 | * Returns true if a blog has more than one category. |
| | 337 | * |
| | 338 | * (Cribbed from _s theme.) |
| | 339 | * |
| | 340 | * @since Twenty Twelve 1.0 |
| | 341 | */ |
| | 342 | function twentytwelve_categorized_site() { |
| | 343 | if ( false === ( $all_the_cool_cats = get_transient( 'twentytwelve_all_the_cool_cats' ) ) ) { |
| | 344 | // Create an array of all the categories that are attached to posts |
| | 345 | $all_the_cool_cats = get_categories( array( |
| | 346 | 'hide_empty' => 1, |
| | 347 | ) ); |
| | 348 | |
| | 349 | // Count the number of categories that are attached to posts |
| | 350 | $all_the_cool_cats = count( $all_the_cool_cats ); |
| | 351 | |
| | 352 | set_transient( 'twentytwelve_all_the_cool_cats', $all_the_cool_cats ); |
| | 353 | } |
| | 354 | |
| | 355 | if ( '1' != $all_the_cool_cats ) { |
| | 356 | // This site has more than 1 category so twentytwelve_categorized_site should return true |
| | 357 | return true; |
| | 358 | } else { |
| | 359 | // This site has only 1 category so twentytwelve_categorized_site should return false |
| | 360 | return false; |
| | 361 | } |
| | 362 | } |
| | 363 | |
| | 364 | /** |
| | 365 | * Flush out the transients used in twentytwelve_categorized_site |
| | 366 | * |
| | 367 | * @since Twenty Twelve 1.0 |
| | 368 | */ |
| | 369 | function twentytwelve_category_transient_flusher() { |
| | 370 | // Like, beat it. Dig? |
| | 371 | delete_transient( 'twentytwelve_all_the_cool_cats' ); |
| | 372 | } |
| | 373 | add_action( 'edit_category', 'twentytwelve_category_transient_flusher' ); |
| | 374 | add_action( 'save_post', 'twentytwelve_category_transient_flusher' ); |
| | 375 | |
| | 376 | |
| | 377 | /** |