WordPress主题修改Twenty Ten头部图片

2012年09月14日

原创内容,转载请注明出处:https://www.myzhenai.com/thread-15088-1-1.html https://www.myzhenai.com.cn/post/761.html


Twenty Ten是WordPress官方团队出的一款优秀的主题,默认主题带了几个头部图片,假如我们想要添加图片或修改它的头部图片要如何动手呢?如果只是修改图片那就好办多了,找个想要替换的图片,首先把图片像表修改成 940px*198px 和 230px*48px 两个规格的图片,假设我们想要替换的图片名称是cherryblossoms.jpg和cherryblossoms-thumbnail.jpg,那么我们只需要把940*198的图片名称改为cherryblossoms.jpg并把230*48的图片名称改为cherryblossoms-thumbnail.jpg,然后把图片上传到/wp-content/themes/twentyten/images/headers/替换原文件即可.可是如果我们想要添加头部图片的话就麻烦一些了,我们需要修改functions.php这个文件,在这个文件里添加一些代码才行.步骤如下:
1:把要添加的图片分别修改成像表为940px*198px,230px*48px两个文件并压缩图片大小.
2:把940px*198px图片名称用英文命名,230px*48px文件名后边加上-thumbnail,不明白的可以参考/wp-content/themes/twentyten/images/headers/这目录里的图片命名规则.
3:将图片上传到/wp-content/themes/twentyten/images/headers/目录下
4:修改/wp-content/themes/twentyten/functions.php文件.
5:保存,上传,替换/wp-content/themes/twentyten/functions.php文件即可.
找到/wp-content/themes/twentyten/functions.php文件里的以下内容

register_default_headers( array(
		'berries' => array(
			'url' => '%s/images/headers/berries.jpg',
			'thumbnail_url' => '%s/images/headers/berries-thumbnail.jpg',
			/* translators: header image description */
			'description' => __( 'Berries', 'twentyten' )
		),
		'cherryblossom' => array(
			'url' => '%s/images/headers/cherryblossoms.jpg',
			'thumbnail_url' => '%s/images/headers/cherryblossoms-thumbnail.jpg',
			/* translators: header image description */
			'description' => __( 'Cherry Blossoms', 'twentyten' )
		),
		'concave' => array(
			'url' => '%s/images/headers/concave.jpg',
			'thumbnail_url' => '%s/images/headers/concave-thumbnail.jpg',
			/* translators: header image description */
			'description' => __( 'Concave', 'twentyten' )
		),
		'fern' => array(
			'url' => '%s/images/headers/fern.jpg',
			'thumbnail_url' => '%s/images/headers/fern-thumbnail.jpg',
			/* translators: header image description */
			'description' => __( 'Fern', 'twentyten' )
		),
		'forestfloor' => array(
			'url' => '%s/images/headers/forestfloor.jpg',
			'thumbnail_url' => '%s/images/headers/forestfloor-thumbnail.jpg',
			/* translators: header image description */
			'description' => __( 'Forest Floor', 'twentyten' )
		),
		'inkwell' => array(
			'url' => '%s/images/headers/inkwell.jpg',
			'thumbnail_url' => '%s/images/headers/inkwell-thumbnail.jpg',
			/* translators: header image description */
			'description' => __( 'Inkwell', 'twentyten' )
		),
		'path' => array(
			'url' => '%s/images/headers/path.jpg',
			'thumbnail_url' => '%s/images/headers/path-thumbnail.jpg',
			/* translators: header image description */
			'description' => __( 'Path', 'twentyten' )
		),
		'sunset' => array(
			'url' => '%s/images/headers/sunset.jpg',
			'thumbnail_url' => '%s/images/headers/sunset-thumbnail.jpg',
			/* translators: header image description */
			'description' => __( 'Sunset', 'twentyten' )
		)
	) );
}

 
例如我要添加五张头部图片,我额外编辑了以下的代码.

'City' => array(
			'url' => '%s/images/headers/City.jpg',
			'thumbnail_url' => '%s/images/headers/City-thumbnail.jpg',
			/* translators: header image description */
			'description' => __( 'City', 'twentyten' )
		),
'Forest' => array(
			'url' => '%s/images/headers/Forest.jpg',
			'thumbnail_url' => '%s/images/headers/Forest-thumbnail.jpg',
			/* translators: header image description */
			'description' => __( 'Forest', 'twentyten' )
		),
'Lawn' => array(
			'url' => '%s/images/headers/Lawn.jpg',
			'thumbnail_url' => '%s/images/headers/Lawn-thumbnail.jpg',
			/* translators: header image description */
			'description' => __( 'Lawn', 'twentyten' )
		),
'River' => array(
			'url' => '%s/images/headers/River.jpg',
			'thumbnail_url' => '%s/images/headers/River-thumbnail.jpg',
			/* translators: header image description */
			'description' => __( 'River', 'twentyten' )
		),
'Tree' => array(
			'url' => '%s/images/headers/Tree.jpg',
			'thumbnail_url' => '%s/images/headers/Tree-thumbnail.jpg',
			/* translators: header image description */
			'description' => __( 'Tree', 'twentyten' )
		),

 
把它们添加到文件代码里的),下方,如添加后全部代码如下

register_default_headers( array(
		'berries' => array(
			'url' => '%s/images/headers/berries.jpg',
			'thumbnail_url' => '%s/images/headers/berries-thumbnail.jpg',
			/* translators: header image description */
			'description' => __( 'Berries', 'twentyten' )
		),
		'City' => array(
			'url' => '%s/images/headers/City.jpg',
			'thumbnail_url' => '%s/images/headers/City-thumbnail.jpg',
			/* translators: header image description */
			'description' => __( 'City', 'twentyten' )
		),
    'Forest' => array(
			'url' => '%s/images/headers/Forest.jpg',
			'thumbnail_url' => '%s/images/headers/Forest-thumbnail.jpg',
			/* translators: header image description */
			'description' => __( 'Forest', 'twentyten' )
		),
    'Lawn' => array(
			'url' => '%s/images/headers/Lawn.jpg',
			'thumbnail_url' => '%s/images/headers/Lawn-thumbnail.jpg',
			/* translators: header image description */
			'description' => __( 'Lawn', 'twentyten' )
		),
    'River' => array(
			'url' => '%s/images/headers/River.jpg',
			'thumbnail_url' => '%s/images/headers/River-thumbnail.jpg',
			/* translators: header image description */
			'description' => __( 'River', 'twentyten' )
		),
    'Tree' => array(
			'url' => '%s/images/headers/Tree.jpg',
			'thumbnail_url' => '%s/images/headers/Tree-thumbnail.jpg',
			/* translators: header image description */
			'description' => __( 'Tree', 'twentyten' )
		),

		'cherryblossom' => array(
			'url' => '%s/images/headers/cherryblossoms.jpg',
			'thumbnail_url' => '%s/images/headers/cherryblossoms-thumbnail.jpg',
			/* translators: header image description */
			'description' => __( 'Cherry Blossoms', 'twentyten' )
		),
		'concave' => array(
			'url' => '%s/images/headers/concave.jpg',
			'thumbnail_url' => '%s/images/headers/concave-thumbnail.jpg',
			/* translators: header image description */
			'description' => __( 'Concave', 'twentyten' )
		),
		'fern' => array(
			'url' => '%s/images/headers/fern.jpg',
			'thumbnail_url' => '%s/images/headers/fern-thumbnail.jpg',
			/* translators: header image description */
			'description' => __( 'Fern', 'twentyten' )
		),
		'forestfloor' => array(
			'url' => '%s/images/headers/forestfloor.jpg',
			'thumbnail_url' => '%s/images/headers/forestfloor-thumbnail.jpg',
			/* translators: header image description */
			'description' => __( 'Forest Floor', 'twentyten' )
		),
		'inkwell' => array(
			'url' => '%s/images/headers/inkwell.jpg',
			'thumbnail_url' => '%s/images/headers/inkwell-thumbnail.jpg',
			/* translators: header image description */
			'description' => __( 'Inkwell', 'twentyten' )
		),
		'path' => array(
			'url' => '%s/images/headers/path.jpg',
			'thumbnail_url' => '%s/images/headers/path-thumbnail.jpg',
			/* translators: header image description */
			'description' => __( 'Path', 'twentyten' )
		),
		'sunset' => array(
			'url' => '%s/images/headers/sunset.jpg',
			'thumbnail_url' => '%s/images/headers/sunset-thumbnail.jpg',
			/* translators: header image description */
			'description' => __( 'Sunset', 'twentyten' )
		)
	) );
}

 


sicnature ---------------------------------------------------------------------
I P 地 址: 3.137.176.213
区 域 位 置: 美国
系 统 信 息: 美国
Original content, please indicate the source:
同福客栈论坛 | 蟒蛇科普海南乡情论坛 | JiaYu Blog
sicnature ---------------------------------------------------------------------
Welcome to reprint. Please indicate the source https://myzhenai.com/post/761.html

没有评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注