gpt4 book ai didi

php - 在 wordpress 的 CSS 中更改选定页面的最有效方法是什么?

转载 作者:行者123 更新时间:2023-11-28 09:42:00 26 4
gpt4 key购买 nike

我想给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);

这应该给你一个想法

关于php - 在 wordpress 的 CSS 中更改选定页面的最有效方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25378077/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com