在Wordpress中每页自定义CSS [英] Custom CSS per page in Wordpress

查看:169
本文介绍了在Wordpress中每页自定义CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好,

我为网站中的某些页面创建了不同的背景和一些其他图像。目前,以下代码在我们网站上的儿童页面上运行良好。

I have created a different background and a few other images for certain pages within our site. Currently the below code is working well with the "kids" page on our site.

<body<?php if ( is_page(array('kids'))) {
echo ' class="kids" '; } ?>>

我试图弄清楚如何将相同的CSS添加到下的其他页面。儿童页面。因此,如果您去参加儿童/集体聚会,我该如何将其添加到代码中以调用该特殊CSS?

I am trying to figure out how to go about adding that same CSS to other pages"under" the kids page. So if you go to kids/block-party, how would I go about adding it to the code to call that special CSS?

我已经尝试了以下

<body<?php if ( is_page(array('kids, kids/block-party'))) {
echo ' class="kids" '; } ?>>

由于某种原因,逗号似乎没有注册。

the comma does not seem to register for some reason.

这是一个wordpress运行站点。

This is a wordpress run site.

谢谢

推荐答案

另一种选择就是简单地替换

Another option is simply replacing

<body>

<body <?php body_class(); ?>>

然后您可以通过css对其进行定位,如下所示:

Then you can target it it via css as follows:

body.page-id-2, body.parent-pageid-2 { background-color: red; }

其中的ID是您要定位的页面/父页面的ID。这样可以使模板保持逻辑清晰,并允许您使用与当前方法相同的自定义选项。

Where the ID is the ID of the page/parent-page you are targeting. This will keep your template clear of logic, and allow you the same customization options your current method is using.

这篇关于在Wordpress中每页自定义CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆