Hide or show a div based on a page

Permalink
I've got a div with a background image that I'd like to only show on the home page. What php would I wrap to hide it from other pages.

Also, If I wanted to selectivly show it on some pages, what php if statement would i wrap the div with as well.

thanks.

 
CC3381 replied on at Permalink Reply 1 Attachment
CC3381
Create a custom attribute (image file) and assign it your homepage and then create an if statement to assign a style to the body tag. I have attached a full default file if you need it.


Danny


<?php 
$page_background_file = $c->getAttribute('page_background');
$bodyStyle = "";
if ($page_background_file instanceof File && $page_background_file->getFileID() > 0) {
    $bodyStyle =
       "style=\"background: url('" .
       $page_background_file->getVersion()->getRelativePath() .
       "'); background-size: cover; background-attachment:fixed; \"";
}
?>
<body <? echo $bodyStyle ?> >
dotman replied on at Permalink Reply
thank you for that. I noticed some similar css for another div in my theme's css and it worked. I used this:

body.homepage #ribbon { position: absolute; width: 256px; height: 122px; top:150px; left: -25px;  hidden; z-index: 1000; background: url(../img/liveit-2.png)}


But I appreciate the lead on that and will try it as well. i need to learn to use attributes more.

thanks.