Advertisement
SergeyBiryukov

Rotating headers support for Delicate theme

Jul 11th, 2011
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.21 KB | None | 0 0
  1. add_action( 'after_setup_theme', 'delicate_setup' );
  2.  
  3. if ( ! function_exists( 'delicate_setup' ) ):
  4. /**
  5.  * Sets up theme defaults and registers support for various WordPress features.
  6.  *
  7.  * @uses add_theme_support() To add support for post thumbnails.
  8.  * @uses add_custom_image_header() To add support for a custom header.
  9.  */
  10. function delicate_setup() {
  11.     // This theme uses Featured Images (also known as post thumbnails) for per-post/per-page Custom Header images
  12.     add_theme_support( 'post-thumbnails' );
  13.  
  14.     // The next four constants set how Delicate supports custom headers.
  15.  
  16.     // The default header text color
  17.     define( 'HEADER_TEXTCOLOR', '000' );
  18.  
  19.     // By leaving empty, we allow for random image rotation.
  20.     define( 'HEADER_IMAGE', '' );
  21.  
  22.     // The height and width of your custom header.
  23.     // Add a filter to delicate_header_image_width and delicate_header_image_height to change these values.
  24.     define('HEADER_IMAGE_WIDTH', 969);
  25.     define('HEADER_IMAGE_HEIGHT', 213);
  26.  
  27.     // We'll be using post thumbnails for custom header images on posts and pages.
  28.     // We want them to be the size of the header image that we just defined
  29.     // Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
  30.     set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );
  31.  
  32.     // Turn on random header image rotation by default.
  33.     add_theme_support( 'custom-header', array( 'random-default' => true ) );
  34.  
  35.     // Add a way for the custom header to be styled in the admin panel that controls
  36.     // custom headers. See delicate_admin_header_style(), below.
  37.     add_custom_image_header( 'delicate_header_style', 'delicate_admin_header_style', 'delicate_admin_header_image' );
  38.  
  39.     // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI.
  40.     register_default_headers( array(
  41.         'green-header' => array(
  42.             'url' => '%s/images/header/header.jpg',
  43.             'thumbnail_url' => '%s/images/header/header.jpg',
  44.             'description' => 'Зелёный'
  45.         ),
  46.         'blue-header' => array(
  47.             'url' => '%s/images/header/headers.jpg',
  48.             'thumbnail_url' => '%s/images/header/headers.jpg',
  49.             'description' => 'Синий'
  50.         )
  51.     ) );
  52. }
  53. endif; // delicate_setup
  54.  
  55. if ( ! function_exists( 'delicate_header_style' ) ) :
  56. /**
  57.  * Styles the header image and text displayed on the blog
  58.  */
  59. function delicate_header_style() {
  60.  
  61.     // If no custom options for text are set, let's bail
  62.     // get_header_textcolor() options: HEADER_TEXTCOLOR is default, hide text (returns 'blank') or any hex value
  63.     if ( HEADER_TEXTCOLOR == get_header_textcolor() )
  64.         return;
  65.     // If we get this far, we have custom styles. Let's do this.
  66.     ?>
  67.     <style type="text/css">
  68.     <?php
  69.         // Has the text been hidden?
  70.         if ( 'blank' == get_header_textcolor() ) :
  71.     ?>
  72.         #site-title,
  73.         #site-description {
  74.             position: absolute !important;
  75.             clip: rect(1px 1px 1px 1px); /* IE6, IE7 */
  76.             clip: rect(1px, 1px, 1px, 1px);
  77.         }
  78.     <?php
  79.         // If the user has set a custom color for the text use that
  80.         else :
  81.     ?>
  82.         #site-title a,
  83.         #site-description {
  84.             color: #<?php echo get_header_textcolor(); ?> !important;
  85.         }
  86.     <?php endif; ?>
  87.     </style>
  88.     <?php
  89. }
  90. endif; // delicate_header_style
  91.  
  92. if ( ! function_exists( 'delicate_admin_header_style' ) ) :
  93. /**
  94.  * Styles the header image displayed on the Appearance > Header admin panel.
  95.  *
  96.  * Referenced via add_custom_image_header() in delicate_setup().
  97.  */
  98. function delicate_admin_header_style() {
  99. ?>
  100.     <style type="text/css">
  101.     .appearance_page_custom-header #headimg {
  102.         border: none;
  103.     }
  104.     #headimg h1,
  105.     #desc {
  106.         font-family: "Helvetica Neue", Arial, Helvetica, "Nimbus Sans L", sans-serif;
  107.     }
  108.     #headimg h1 {
  109.         margin: 0;
  110.     }
  111.     #headimg h1 a {
  112.         font-size: 32px;
  113.         line-height: 36px;
  114.         text-decoration: none;
  115.     }
  116.     #desc {
  117.         font-size: 14px;
  118.         line-height: 23px;
  119.         padding: 0 0 3em;
  120.     }
  121.     <?php
  122.         // If the user has set a custom color for the text use that
  123.         if ( get_header_textcolor() != HEADER_TEXTCOLOR ) :
  124.     ?>
  125.         #site-title a,
  126.         #site-description {
  127.             color: #<?php echo get_header_textcolor(); ?>;
  128.         }
  129.     <?php endif; ?>
  130.     #headimg img {
  131.         max-width: 1000px;
  132.         height: auto;
  133.         width: 100%;
  134.     }
  135.     </style>
  136. <?php
  137. }
  138. endif; // delicate_admin_header_style
  139.  
  140. if ( ! function_exists( 'delicate_admin_header_image' ) ) :
  141. /**
  142.  * Custom header image markup displayed on the Appearance > Header admin panel.
  143.  *
  144.  * Referenced via add_custom_image_header() in delicate_setup().
  145.  */
  146. function delicate_admin_header_image() { ?>
  147.     <div id="headimg">
  148.         <?php
  149.         if ( 'blank' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) || '' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) )
  150.             $style = ' style="display:none;"';
  151.         else
  152.             $style = ' style="color:#' . get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) . ';"';
  153.         ?>
  154.         <h1><a id="name"<?php echo $style; ?> onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo( 'name' ); ?></a></h1>
  155.         <div id="desc"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></div>
  156.         <?php $header_image = get_header_image();
  157.         if ( ! empty( $header_image ) ) : ?>
  158.             <img src="<?php echo esc_url( $header_image ); ?>" alt="" />
  159.         <?php endif; ?>
  160.     </div>
  161. <?php }
  162. endif; // delicate_admin_header_image
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement