Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2015
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.90 KB | None | 0 0
  1. if(!function_exists('nabia_custom_bg')) {
  2.     function nabia_custom_bg() {
  3.         global $post;
  4.  
  5.         if( is_singular(array('post', 'page')) && get_post_meta( $post->ID, 'nabia_cmb_post_bimg', true) ) {
  6.             $background = get_post_meta( $post->ID, 'nabia_cmb_post_bimg', true);
  7.         } else {
  8.             $background = get_background_image();
  9.         }
  10.         if( is_singular(array('post', 'page')) && get_post_meta( $post->ID, 'nabia_cmb_post_bg_color', true) ) {
  11.             $color = get_post_meta($post->ID, 'nabia_cmb_post_bg_color', true);
  12.         } else {
  13.             $color = get_background_color();
  14.         }
  15.  
  16.         if ( ! $background && ! $color )
  17.             return;
  18.      
  19.         if( is_singular(array('post', 'page')) && get_post_meta( $post->ID, 'nabia_cmb_post_bg_color', true) ) {
  20.             $style = $color ? "background-color: $color;" : '';
  21.         } else {
  22.             $style = $color ? "background-color: #$color;" : '';
  23.         }
  24.      
  25.         if ( $background ) {
  26.             $image = " background-image: url($background);";
  27.      
  28.  
  29.             if( is_singular(array('post', 'page')) && get_post_meta( $post->ID, 'nabia_cmb_post_bg_repeat', true) && get_post_meta( $post->ID, 'nabia_cmb_post_bimg', true) ) {
  30.                 $repeat = get_post_meta( $post->ID, 'nabia_cmb_post_bg_repeat', true);
  31.             } else {
  32.                 $repeat = nabia_theme_mod( 'background_repeat' );
  33.             }
  34.  
  35.             if ( ! in_array( $repeat, array( 'no-repeat', 'repeat-x', 'repeat-y', 'repeat' ) ) )
  36.                 $repeat = 'repeat';
  37.      
  38.             $repeat = " background-repeat: $repeat;";
  39.      
  40.             if( is_singular(array('post', 'page')) && get_post_meta( $post->ID, 'nabia_cmb_post_bg_position', true) && get_post_meta( $post->ID, 'nabia_cmb_post_bimg', true) ) {
  41.                 $position = get_post_meta( $post->ID, 'nabia_cmb_post_bg_position', true);
  42.             } else {
  43.                 $position = nabia_theme_mod( 'background_position_x' );
  44.             }
  45.      
  46.             if ( ! in_array( $position, array( 'center', 'right', 'left' ) ) )
  47.                 $position = 'left';
  48.      
  49.             $position = " background-position: top $position;";
  50.      
  51.             if( is_singular(array('post', 'page')) && get_post_meta( $post->ID, 'nabia_cmb_post_bg_attachament', true) && get_post_meta( $post->ID, 'nabia_cmb_post_bimg', true) ) {
  52.                 $attachment = get_post_meta( $post->ID, 'nabia_cmb_post_bg_attachament', true);
  53.             } else {
  54.                 $attachment = nabia_theme_mod( 'background_attachment' );
  55.             }
  56.      
  57.             if ( ! in_array( $attachment, array( 'fixed', 'scroll' ) ) )
  58.                 $attachment = 'scroll';
  59.      
  60.             $attachment = " background-attachment: $attachment;";
  61.      
  62.             $style .= $image . $repeat . $position . $attachment;
  63.         }
  64.         ?>
  65.         <style type="text/css">
  66.         body.custom-background { <?php echo esc_attr( $style ); ?> }
  67.         </style>
  68.  
  69.     <?php
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement