Hi guys,
I need to change the background color of my site, only blog page (home.php).
I have changed this class .tm-main in the style.css of my my child theme.
1) I have inserted this code for all page:
.tm-main {
background-color: #fff;
}
2) Now i want apply this another rule only for home.php.
.tm-main {
background-color: #f5f5f5;
}
How can I do?
Fabio
You can use Conditional Tag is_home(). Ex:
// Setup homepage bg color
beans_add_smart_action( 'wp', 'fabio_setup_bgcolor' );
function fabio_setup_bgcolor() {
if (is_home())
beans_add_attribute( 'beans_main', 'class', 'bg-color' );
}
Then add CSS for
.bg-color
Thank you Trung Nguyen. I've solved.
Which way Fabio?
I used your solution:
I've change my idea, and i decided to apply on all wordpress pages one type background, while apply another background on all post /articles.
So I solved with your solution , like this...
In my function.php this:
// Setup all pages bg color
beans_add_smart_action( 'wp', 'fabio_setup_bgcolor' );
function fabio_setup_bgcolor() {
if (is_page())
beans_add_attribute( 'beans_main', 'class', 'bg-color' );
}
In my style.css this:
/* main background color for every posts */
.tm-main { background-color: #f5f5f5; }
/*background color for all pages*/
.bg-color { background-color: #fff; }
Thank you
God job!
By the way, amazing website, buddy (Fabiographic) π
Ahahahah, Thanks so much, friend! π
Hey guys,
The solution to add a class on home is good and shows your great understanding of how Beans work π For that specific case though, note that WordPress automaticall adds a home
class to the body
markup on the home page. So without add a class via PHP, you could simply add the following CSS:
/* Main background color for every posts. */
.tm-main {
background-color: #f5f5f5;
}
/* Background color for the home page */
.home .tm-main {
background-color: #fff;
}
Happy coding,
Wow, too fast.
@Thierry: How do I have deep understanding about WordPress like you? (really need a advice, I worked hard with WordPress but there are many things that i don't know about WP)
Hi Trung, the best advise I can give is to continue building cool things. It is the best way to learn! It doesn't come overnight though, I have been writing code for WordPress for close to a decade and I am still discovering new stuff everyday π
Keep up the good work,
Thanks very much brother. I want to discovering Beans source code. but i don't know where to start.
Any suggestion for me, Thierry?
Hey Trung,
Beans Core may seem a bit complex but it is actually well organized and follow the same logic throughout the framework. I would start by reading this article to understand the basic and then start by looking in the lib/init.php
which is where everything starts π
Have fun,