成都公司:成都市成華區(qū)建設(shè)南路160號(hào)1層9號(hào)
重慶公司:重慶市江北區(qū)紅旗河溝華創(chuàng)商務(wù)大廈18樓
當(dāng)前位置:工程項(xiàng)目OA系統(tǒng) > 泛普各地 > 湖南OA系統(tǒng) > 株洲OA > 株洲網(wǎng)站建設(shè)公司
WP3.4版本Custom Backgrounds和Custom Headers的新方法
申請(qǐng)免費(fèi)試用、咨詢電話:400-8352-114
天收到WordPress官方郵件通知,WordPress 3.4會(huì)用新的方法實(shí)現(xiàn)Custom Backgrounds(自定義背景)和Custom Headers(自定義頭部-一般是圖片),老方法可以繼續(xù)使用但不提倡。Custom Backgrounds
原來的方法:
add_custom_background();
新的方法:
add_theme_support('custom-background');
新方法加了數(shù)組參數(shù),定義更容易:add_theme_support('custom-background', $args ),$args 默認(rèn)參數(shù)如下:

$defaults = array(
'default-image' => '', //默認(rèn)背景圖片
'default-color' => '', //默認(rèn)背景顏色
'wp-head-callback' => '_custom_background_cb', //回調(diào)函數(shù)
'admin-head-callback' => '',
'admin-preview-callback' => ''
)
現(xiàn)在定義默認(rèn)背景圖片和顏色變得非常簡(jiǎn)單:
add_theme_support( 'custom-background', array(
// Background color default
'default-color' => '000',
// Background image default
'default-image' => get_template_directory_uri() . '/images/background.jpg'
) );
Custom Headers
老方法:
// Define default header image constant
define( 'HEADER_IMAGE', get_template_directory_uri() . '/images/headers/default.jpg' );
// Define header image width constant
define( 'HEADER_IMAGE_WIDTH', 1000 );
// Define header image height constant
define( 'HEADER_IMAGE_HEIGHT', 198 );
// Define header text constant
define( 'NO_HEADER_TEXT', false );
// Define header text color constant
define( 'HEADER_TEXTCOLOR', '000' );
// Turn on random header image rotation by default.
// Requires HEADER_IMAGE to be null
add_theme_support( 'custom-header', array( 'random-default' => true ) );
// Add Theme support
add_custom_image_header( $wphead_cb, $adminhead_cb, $adminpreview_cb );
新方法:
add_theme_support( 'custom-header', array(
// Header image default
'default-image' => get_template_directory_uri() . '/images/headers/default.jpg',
// Header text display default
'header-text' => false,
// Header text color default
'default-text-color' => '000',
// Header image width (in pixels)
'width' => 1000,
// Header image height (in pixels)
'height' => 198,
// Header image random rotation default
'random-default' => false,
// Template header style callback
'wp-head-callback' => $wphead_cb,
// Admin header style callback
'admin-head-callback' => $adminhead_cb,
// Admin preview style callback
'admin-preview-callback' => $adminpreview_cb
) );
現(xiàn)在參數(shù)定義更簡(jiǎn)單,對(duì)比一下新舊參數(shù):
HEADER_IMAGE => 'default-image'
HEADER_IMAGE_WIDTH => 'width'
HEADER_IMAGE_HEIGHT => 'height'
NO_HEADER_TEXT => 'header-text'
HEADER_TEXTCOLOR => 'default-text-color'
下面是完整的參數(shù)參考:
$defaults = array(
'default-image' => '',
'random-default' => false,
'width' => 0,
'height' => 0,
'flex-height' => false,
'flex-width' => false,
'default-text-color' => '',
'header-text' => true,
'uploads' => true,
'wp-head-callback' => '',
'admin-head-callback' => '',
'admin-preview-callback' => '',
);
看來下次升級(jí)主題時(shí)就要更新這個(gè)了。
英文好的朋友還是去看原文:<傳送門>

