我想在wordpress中将背景图片添加到一组页面中。
我想向另一组页面添加不同的背景图片
目前,我正在使用PageID将其应用于每个单独的页面,如下面的代码所示。由于有超过1000页。是否有更简单的方法应用于每组页面?
.page-id-264 #header .logo a,
.page-id-272 #header .logo a {
background-image: url("http://www.richcoward.com/newcges/wp-content/uploads/2014/08/NWU-No-Frame.png") !important;
background-size: 100% !important;
background-repeat: no-repeat !important;
height: 86px !important;
width: 416px !important;
}
谢谢你的帮助
最佳答案
这是一个简单的解决方案。
在主题文件夹中创建一个自定义的CSS(例如mystyle.css)文件。加
#header .logo a {
background-image: url("http://www.richcoward.com/newcges/wp-content/uploads/2014/08/NWU-No-Frame.png") !important;
background-size: 100% !important;
background-repeat: no-repeat !important;
height: 86px !important;
width: 416px !important;
}
进入您的mystyle.css。现在,打开您的functions.php并有条件地入队样式表。使用
is_page()
或is_page_template()
条件检查。我相信您在谈论的是页面组,因此我可以想象您为特定的组使用特定的页面模板,因此我倾向于使用is_page_template
function enqueue_custom_style() {
if(is_page_template('page-whatever.php')) {
wp_enqueue_style('my-style', get_stylesheet_directory_uri() . '/mystyle.css' );
}
}
add_action('wp_enqueue_scripts', 'enqueue_custom_style', 999);
这应该给你一个想法