2012-06-19 3 views
0

저는 사용자 정의 배경을 가진 Wordpress Theme를 코딩하고 있습니다 만, WP 문서에는 각 배경 매개 변수 (이미지, 색상, 위치 등)에 대한 값을 검색하는 기능에 대한 정보가 없습니다. 단지 get_background_color 밖에 없습니다. 및 get_background_image. Wordpress 3.4의 사용자 정의 배경 지원 기능은 무엇입니까?

사용자 정의 배경을 지원하기위한 코드입니다

$custom_background_support = array(
    'default-color'   => 'FFF', 
    'default-image'   => '', 
    'wp-head-callback'  => 'custom_background_cb' 
); 

if (is_wp_version('3.4')) 
    add_theme_support('custom-background', $custom_background_support); 
else 
    add_custom_background($custom_background_support); 

그리고 이것은 콜백입니다 :

function academia_custom_background_cb() 
{ 
?> 
<style type="text/css"> 
body{ 
background-color: #<?=get_background_color();?> !important; 
background-image: url('<?=get_background_image();?>'); 
background-position: ... 
background-repeat: ... 
... 
}</style> 
<?php 
} 

편집 :이 내가하는 데 필요한 값이다. 이 스크린 샷은 모양 -> 배경입니다.

Appearance -> Background

답변

1

오래된 질문,하지만 같은 정보를 내 Google 검색에서왔다. Krike의 대답을 끝내면, 그것은 참으로 get_theme_mod()

당신은 직장에서 기본값 인 wp-head-callback을 볼 수 있습니다.

/** 
* Default custom background callback. 
* 
* @since 3.0.0 
* @access protected 
*/ 
function _custom_background_cb() { 
    // $background is the saved custom image, or the default image. 
    $background = set_url_scheme(get_background_image()); 

    // $color is the saved custom color. 
    // A default has to be specified in style.css. It will not be printed here. 
    $color = get_theme_mod('background_color'); 

    if (! $background && ! $color) 
     return; 

    $style = $color ? "background-color: #$color;" : ''; 

    if ($background) { 
     $image = " background-image: url('$background');"; 

     $repeat = get_theme_mod('background_repeat', 'repeat'); 
     if (! in_array($repeat, array('no-repeat', 'repeat-x', 'repeat-y', 'repeat'))) 
      $repeat = 'repeat'; 
     $repeat = " background-repeat: $repeat;"; 

     $position = get_theme_mod('background_position_x', 'left'); 
     if (! in_array($position, array('center', 'right', 'left'))) 
      $position = 'left'; 
     $position = " background-position: top $position;"; 

     $attachment = get_theme_mod('background_attachment', 'scroll'); 
     if (! in_array($attachment, array('fixed', 'scroll'))) 
      $attachment = 'scroll'; 
     $attachment = " background-attachment: $attachment;"; 

     $style .= $image . $repeat . $position . $attachment; 
    } 
?> 
<style type="text/css" id="custom-background-css"> 
body.custom-background { <?php echo trim($style); ?> } 
</style> 
<?php 
} 

그래서 당신과 같이 반복, 위치 및 첨부 파일을 얻을 것 :
$repeat = get_theme_mod('background_repeat', 'repeat'); 
$position = get_theme_mod('background_position_x', 'left'); 
$attachment = get_theme_mod('background_attachment', 'scroll'); 

나는 두 번째 매개 변수가 기본값입니다 가정합니다.