Advertisement
Digitalraindrops

Category Header

Jul 24th, 2011
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.67 KB | None | 0 0
  1. <?php
  2.  
  3. //This goes in header.php where the header image is loaded.
  4.  
  5. $slug="";
  6. if ( is_category() ) {
  7.     /* category.php or archive.php */
  8.     global $cat;
  9.     $curr_cat = get_category($cat);
  10.     $slug = $curr_cat->slug;
  11. } elseif ( is_single() ) {
  12.     /* It is a post get the first category header */
  13.     global $post;
  14.     $categories = get_the_category($post->ID);
  15.     if($categories) {
  16.         $slug = $categories[0]->slug;
  17.     }      
  18. }
  19. if ($slug) {
  20.     //load header image
  21.     if(file_exists( STYLESHEETPATH .'/images/headers/' .$slug .'.png') ) {
  22.         $imguri = get_stylesheet_directory_uri() .'/images/headers/' .$slug .'.png';
  23.         ?>
  24.         <!-- Here is where the header image html would be -->
  25.         <?php
  26.     }
  27. }
  28. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement