Stub-Specific Body-Tag IDs for b2evolution

Published by Andrew Hreschak in Web Development, b2evolution 0.9.x, b2evolution 1.10.x, CSS, PHP
Published on 08/05/07 @ 07:25:00 pm using 254 words, and has 44207 views

A while back I found myself needing the ability to uniquely identify each blog on my b2evolution system. I wanted to be able to display blog-specific CSS styles and header imagery, while using the same b2evo skin across the entire site, rather than developing slightly varied skins for each blog.

The solution is rather simple, and allows each blog to be styled uniquely, while still allowing the remaining stylesheet definitions to cascade over elements which are not called by the unique identifier. So... on to the code...

Adding the following code to your b2evo skin's /skinname/_main.php file will cause the 'body' tag to be ID'd with the '$blog_shortname' of the specific blog. Essentially, this will ID the body tag as id=1 for Blog All, id=2 for Blog A, and so on....

The following code will work on b2evo 0.9.x...

<body id="<?php echo $Blog->disp( 'shortname' ) ?>">

...and the following code works in b2evolution 1.10.x...

<body id="blog<?php echo $blog ?>">

Once this code has been implemented in the _main.php file of your favorite b2evo skin, you can assign blog-specific styles to your CSS stylesheet as so:

body#blog2 #header {
background: #000 url(images/blog2header.jpg) top center no-repeat;
text-align: left;
}
body#blog3 #header {
background: #000 url(images/blog3header.jpg) top center no-repeat;
text-align: right;
}

The CSS style shown above works with the second PHP example, and can be used in b2evolution 1.10.x blogs...

Contemporaneous Auditory Narcotics:
or, What my speakers are currently pumping...
Decoder & Substance - Heist / Curvature

Creative Commons LicenseThis post is the creative work of Yours Truly and is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 License.

1 comment

Comment from: Torben [Visitor]  
Torben

I liked this a lot - thanks for providing it - for b2evolution 3.3.1 I changed the body tag to be:

<body id="blog <?php echo $Blog->ID ?>">

09/14/09 @ 00:09