View Full Version : Custom banner image and colors for each category
mbrady
Jul-04-2005, 04:36 PM
I had a situation with cobranding where I wanted to have a different banner image and color scheme for each category page. The smugmug customization does allow a custom header and style attributes for colors, but they're global across your whole account.
I've worked out a way to sort of cheat and get this to work (with a few limitations). I figured I would share it here in case this would come in handy for others looking for something similar.
First off, to see the end result, go to http://www.ruama.com (http://www.ruama.com/)
In plain English, what I did was create a script that runs each time the page loads that checks the url and if it finds specific words (corresponding to the category names in my case) and changes the img tag to show a different image. It also changes the background color style attribute. This same technique could be used on a per gallery basis too (anything that has a unique url really). Although the script could get lengthy if you have a whole lot of possible different sections.
There are a couple downsides though. For one, since the script doesn't run until the page is finished loading, there can be a short period of time (depends on connection speed and how much there is on the page to load) as the page is loading where the banner image is not shown and the colors are not set. Then when the page finished loading, the banner image and new colors pop into place. That can be a little goofy, but without having separate headers for each page, there's not a whole lot that can be done about it. Personally it doesn't bug me too much.
Another downside, is that when actually viewing the actual galleries and photos themselves, you don't get the custom settings (doing url comparisons for all that would be prohibitive). In my case, I only want the banner image on the main category page anyway, so I prefer that anyway. It would be nice to keep the color scheme though.
And now for a more detailed explanation (you can view source on the pages to see everything in place if you're curious).
I set up a custom header with a simple table. I set the ID property of the TD cell that I want to hold the image to "bannerCell".
I change the Body tag to run a script when the onload even fires:
<body onload="setBanner()" >
In my Javascript section I put in the setBanner function that checks the url:
function setBanner() {
var url = window.location.href;
// Determine which banner image to show
switch (true) {
case url == 'http://ruama.smugmug.com/' || url == 'http://www.ruama.com/':
// Home page banner
bannerCell.innerHTML = "<img src='http://www.ruama.com/photos/25437157-O.jpg'>";
break;
case url.indexOf('Disney') > -1:
// Disney page
bannerCell.innerHTML = "<img src='http://www.ruama.com/photos/25427988-O.jpg'>";
document.body.style.backgroundColor='#9966FF';
break;
case url.indexOf('Everything') > -1:
// Everything Else page
bannerCell.innerHTML = "<img src='http://www.ruama.com/photos/25427990-O.jpg'>";
document.body.style.backgroundColor='#A6C5A5';
break;
case url.indexOf('Cats') > -1:
// Cats page
bannerCell.innerHTML = "<img src='http://www.ruama.com/photos/25427991-O.gif'>";
document.body.style.backgroundColor = '#c0c0c0';
break;
case url.indexOf('Trips') > -1:
// Trips page
bannerCell.innerHTML = "<img src='http://www.ruama.com/photos/25438543-O.gif'>";
document.body.style.backgroundColor='#9999FF';
break;
default:
// Any other page - no banner graphic
bannerCell.style.display = 'NONE';
}
}
if you've done any basic Javascript programming it should be fairly self-explanatory, but if you want more details, feel free to ask.
I'm sure there are several ways this could be tweaked to fit other similar situations too.
Matt
Barb
Jul-04-2005, 07:12 PM
First off, to see the end result, go to http://www.ruama.com (http://www.ruama.com/)
There are a couple downsides though. For one, since the script doesn't run until the page is finished loading, there can be a short period of time (depends on connection speed and how much there is on the page to load) as the page is loading where the banner image is not shown and the colors are not set. Then when the page finished loading, the banner image and new colors pop into place. That can be a little goofy, but without having separate headers for each page, there's not a whole lot that can be done about it. Personally it doesn't bug me too much.
Matt
Hi Matt:
Very interesting what you've done! Very clever indeed :)
The page-loading delay isn't bad. I'm on broadband and it loaded very quickly.
I think it looks great!
hutch
Sep-05-2005, 08:43 PM
With the most recent changes... is this possible without javascript? Can we now target the banner image with a css tag with code specific for a gallery?
I had a situation with cobranding where I wanted to have a different banner image and color scheme for each category page. The smugmug customization does allow a custom header and style attributes for colors, but they're global across your whole account.
I've worked out a way to sort of cheat and get this to work (with a few limitations). I figured I would share it here in case this would come in handy for others looking for something similar.
First off, to see the end result, go to http://www.ruama.com (http://www.ruama.com/)
In plain English, what I did was create a script that runs each time the page loads that checks the url and if it finds specific words (corresponding to the category names in my case) and changes the img tag to show a different image. It also changes the background color style attribute. This same technique could be used on a per gallery basis too (anything that has a unique url really). Although the script could get lengthy if you have a whole lot of possible different sections.
There are a couple downsides though. For one, since the script doesn't run until the page is finished loading, there can be a short period of time (depends on connection speed and how much there is on the page to load) as the page is loading where the banner image is not shown and the colors are not set. Then when the page finished loading, the banner image and new colors pop into place. That can be a little goofy, but without having separate headers for each page, there's not a whole lot that can be done about it. Personally it doesn't bug me too much.
Another downside, is that when actually viewing the actual galleries and photos themselves, you don't get the custom settings (doing url comparisons for all that would be prohibitive). In my case, I only want the banner image on the main category page anyway, so I prefer that anyway. It would be nice to keep the color scheme though.
And now for a more detailed explanation (you can view source on the pages to see everything in place if you're curious).
I set up a custom header with a simple table. I set the ID property of the TD cell that I want to hold the image to "bannerCell".
I change the Body tag to run a script when the onload even fires:
<body onload="setBanner()" >
In my Javascript section I put in the setBanner function that checks the url:
function setBanner() {
var url = window.location.href;
// Determine which banner image to show
switch (true) {
case url == 'http://ruama.smugmug.com/' || url == 'http://www.ruama.com/':
// Home page banner
bannerCell.innerHTML = "<img src='http://www.ruama.com/photos/25437157-O.jpg'>";
break;
case url.indexOf('Disney') > -1:
// Disney page
bannerCell.innerHTML = "<img src='http://www.ruama.com/photos/25427988-O.jpg'>";
document.body.style.backgroundColor='#9966FF';
break;
case url.indexOf('Everything') > -1:
// Everything Else page
bannerCell.innerHTML = "<img src='http://www.ruama.com/photos/25427990-O.jpg'>";
document.body.style.backgroundColor='#A6C5A5';
break;
case url.indexOf('Cats') > -1:
// Cats page
bannerCell.innerHTML = "<img src='http://www.ruama.com/photos/25427991-O.gif'>";
document.body.style.backgroundColor = '#c0c0c0';
break;
case url.indexOf('Trips') > -1:
// Trips page
bannerCell.innerHTML = "<img src='http://www.ruama.com/photos/25438543-O.gif'>";
document.body.style.backgroundColor='#9999FF';
break;
default:
// Any other page - no banner graphic
bannerCell.style.display = 'NONE';
}
}
if you've done any basic Javascript programming it should be fairly self-explanatory, but if you want more details, feel free to ask.
I'm sure there are several ways this could be tweaked to fit other similar situations too.
Matt
{JT}
Sep-05-2005, 10:16 PM
Yes this is possible without javascript; BUT ... I messed up and the CSS class for the cat/subcat pages is coming soon. So wait a few days and this will be easier without javascript.
With the most recent changes... is this possible without javascript? Can we now target the banner image with a css tag with code specific for a gallery?
Mike Lane
Sep-06-2005, 01:13 AM
Take a look at the <body> tag for each page. You will see that the body tag has a class associated with it for each different type of page (except gallery and category pages which will be fixed soon). So on your homepage you have: <body class="homepage">. In your gallery pages you have (for example): <body class="smugmug_small gallery_XXXXXX category_Object">.
That means that you can style a whole page based upon the type of gallery (the smugmug_small would change to smugmug, journal, default, allthumbs, singleImage - small, medium, and large, and so on depending on the gallery style) and via individual galleries themselves. Furthermore, this is in the body id (and there is a wrapper div that contains the smugmug generated items) that echos this body tag.
What can you do? Well lets say for example that you wanted to change up your gallery style based on the style chosen by the user. Check out one of my galleries: http://www.mikelanephotography.com/gallery/641933. Switch the gallery styles in the top right. Notice how my cobranding changes with the gallery style. Switch it to slideshow, the whole page is completely different colors and everything.
You could even change up one specific gallery entirely. Say you had baby pictures in a gallery, you could change that gallery up to revolve around that (colors that aren't necessarily on the rest of your site or even different headers and footers, whatever). Maybe you have cat pictures in another gallery, you could do the same thing for that gallery and that gallery only if you so chose to.
The best thing is that this doesn't take one iota of javascript to do. Everything can be done using only CSS.
hutch
Sep-06-2005, 06:37 AM
Excellent! Can't wait.
Yes this is possible without javascript; BUT ... I messed up and the CSS class for the cat/subcat pages is coming soon. So wait a few days and this will be easier without javascript.
hutch
Sep-06-2005, 06:40 AM
Makes sense. I was successful playing with the gallery specific formatting, but I put this in the gallery description. I could not find any tags to change the header banner though. I a guessing that these are the tags that JT is referencing as coming soon?
Take a look at the <body> tag for each page. You will see that the body tag has a class associated with it for each different type of page (except gallery and category pages which will be fixed soon). So on your homepage you have: <body class="homepage">. In your gallery pages you have (for example): <body class="smugmug_small gallery_XXXXXX category_Object">.
That means that you can style a whole page based upon the type of gallery (the smugmug_small would change to smugmug, journal, default, allthumbs, singleImage - small, medium, and large, and so on depending on the gallery style) and via individual galleries themselves. Furthermore, this is in the body id (and there is a wrapper div that contains the smugmug generated items) that echos this body tag.
What can you do? Well lets say for example that you wanted to change up your gallery style based on the style chosen by the user. Check out one of my galleries: http://www.mikelanephotography.com/gallery/641933. Switch the gallery styles in the top right. Notice how my cobranding changes with the gallery style. Switch it to slideshow, the whole page is completely different colors and everything.
You could even change up one specific gallery entirely. Say you had baby pictures in a gallery, you could change that gallery up to revolve around that (colors that aren't necessarily on the rest of your site or even different headers and footers, whatever). Maybe you have cat pictures in another gallery, you could do the same thing for that gallery and that gallery only if you so chose to.
The best thing is that this doesn't take one iota of javascript to do. Everything can be done using only CSS.
Mike Lane
Sep-06-2005, 08:00 AM
Makes sense. I was successful playing with the gallery specific formatting, but I put this in the gallery description. I could not find any tags to change the header banner though. I a guessing that these are the tags that JT is referencing as coming soon?
These gallery specific and gallery style specific tags are in every gallery page that you have. Additionally, there is a homepage, keyword, and a class for each size of the single image. In fact, there are probably more that I haven't even found yet. The only issue is the omission of category and gallery keywords in the body class of the respective pages. So you can change your header (or, in fact, your entire page from top to bottom) on each and every page except for those ones. And those'll be fixed soon enough. :D
bigwebguy
Sep-06-2005, 08:03 AM
Makes sense. I was successful playing with the gallery specific formatting, but I put this in the gallery description. I could not find any tags to change the header banner though. I a guessing that these are the tags that JT is referencing as coming soon? The tag that {JT} is referencing is the category_object class tag, where "object" should be the name of the category. Once he fixes that, you can put stuff in your stylesheet like: (assuming you have a category named vacation)
body.category_vacation {
background-color: limegreen;
}
However, to be able to change the header image in your co-brand header, you'll need to give it an ID. You'll also have to use the spacer.gif image to set the size for your header image.
co-branding header code:
<div id="cbHead">
<img src="/img/spacer.gif" width="XX" height="XX" border="0" id="cbImg" />
</div>
Now use the following css code to set the background image. What you'll actually be doing is changing out the background image behind a transparent image. (assume your header image has an id of #cbImg)
css code:
.category_vacation #cbImg {
background: url(http://my.image.url) no-repeat;
}
mbrady
Sep-06-2005, 09:27 AM
Excellent! Can't wait.
Originally Posted by {JT}
Yes this is possible without javascript; BUT ... I messed up and the CSS class for the cat/subcat pages is coming soon. So wait a few days and this will be easier without javascript.
Hi! I got your PM about this and was going to mention the new changes that'll make this possible without the Javascript, but I see it's already popped up here. I'm eager to get rid of the script on my page as soon as the classes for the category pages are in place.
Matt
Mike Lane
Sep-06-2005, 10:32 AM
The tag that {JT} is referencing is the category_object class tag, where "object" should be the name of the category. Once he fixes that, you can put stuff in your stylesheet like: (assuming you have a category named vacation)
body.category_vacation {
background-color: limegreen;
}
However, to be able to change the header image in your co-brand header, you'll need to give it an ID. You'll also have to use the spacer.gif image to set the size for your header image.
co-branding header code:
<div id="cbHead">
<img src="/img/spacer.gif" width="XX" height="XX" border="0" id="cbImg" />
</div>
Now use the following css code to set the background image. What you'll actually be doing is changing out the background image behind a transparent image. (assume your header image has an id of #cbImg)
css code:
.category_vacation #cbImg {
background: url(http://my.image.url) no-repeat;
}
:agree
Anything on the page that you assign a class or id to can be adjusted in this manner. Check out http://www.mikelanephotography.com/gallery/641933/1/27661941/Small and http://www.mikelanephotography.com/gallery/641933/1/27661941/Large. Everything including changing the the header and footer is done with the same CSS file. (The medium sized page and the small page in IE still need a little love, I know...)
Mike
hutch
Sep-06-2005, 12:03 PM
However, to be able to change the header image in your co-brand header, you'll need to give it an ID. You'll also have to use the spacer.gif image to set the size for your header image.
co-branding header code:
<div id="cbHead">
<img src="/img/spacer.gif" width="XX" height="XX" border="0" id="cbImg" />
</div>
Okay, I am slightly lost. I currently have this in the header:
<div align="center">
<img src="http://hutchins.smugmug.com/photos/29139627-L.jpg" width="800" height="183">
</div>
Can I simply add the id tags that you mention to this code?
What code would I then add to a page specific stylesheet to make this graphic not appear? Or change it? Right now, I am importing a stylesheet from another server based on some code in the gallery description.
Now use the following css code to set the background image. What you'll actually be doing is changing out the background image behind a transparent image. (assume your header image has an id of #cbImg)
css code:
.category_vacation #cbImg {
background: url(http://my.image.url) no-repeat;
}
So if I understand you correctly, your suggestion is basically to not assign a standard header image but put a transparent placeholder there and then put various background images depending on the gallery or category?
I am assuming that this means that no other background images or patterns can be placed on the page with this method?
Mike Lane
Sep-06-2005, 12:44 PM
Okay, I am slightly lost. I currently have this in the header:
<div align="center">
<img src="http://hutchins.smugmug.com/photos/29139627-L.jpg" width="800" height="183">
</div>
Can I simply add the id tags that you mention to this code?
Consider changing it to this:
<div id="myHeader">
<img src="/img/spacer.gif" width="XXX" height="YYY" />
</div>
Then add this to the CSS (for example) to set the header for gallery_123456:
.gallery_123456 #myHeader {
Background:url(http://www.mysupercoollogo.com/image.jpg) no-repeat;
width:XXXpx; /* header image width */
height:YYYpx; /* header image height */
margin:0 auto; /* center that header image */
}
Want a different header for gallery_234567? Just add this to the CSS too:
.gallery_234567 #myHeader {
Background:url(http://www.mysupercoollogo.com/image2.jpg) no-repeat;
width:ZZZpx;
width:AAApx;
margin:0 auto;
}
Want a different logo for the smugmug_small style? Change .gallery_234567 to .smugmug_small in the example above and add that to the CSS. etc etc etc.
Want no logo at all in the single image gallery? Add this to the CSS:
.singleImage #myHeader {
display:none;
}
So if I understand you correctly, your suggestion is basically to not assign a standard header image but put a transparent placeholder there and then put various background images depending on the gallery or category?
This is the easiest way to do it.
I am assuming that this means that no other background images or patterns can be placed on the page with this method?
No other background images can be added to the #myHeader layer. If you wanted some other element that would change depending on the gallery or gallery style (etc etc etc) you could add a layer to the #myHeader layer that would have its own class or id and then you'd reference it the same way. This literally makes the cobranding you can do limitless.
Take a look at my page, I've got tons of backgrounds on the page everywhere done just the same way that we're talking about here.
hutch
Sep-06-2005, 01:30 PM
I'll give this a shot. Is it possible to setup a default banner image in the main header, but then override it for specific pages? Rather then explicitly defining one for each gallery?
Consider changing it to this:
<div id="myHeader">
<img src="/img/spacer.gif" width="XXX" height="YYY" />
</div>
Then add this to the CSS (for example) to set the header for gallery_123456:
.gallery_123456 #myHeader {
Background:url(http://www.mysupercoollogo.com/image.jpg) no-repeat;
width:XXXpx; /* header image width */
height:YYYpx; /* header image height */
margin:0 auto; /* center that header image */
}
Want a different header for gallery_234567? Just add this to the CSS too:
.gallery_234567 #myHeader {
Background:url(http://www.mysupercoollogo.com/image2.jpg) no-repeat;
width:ZZZpx;
width:AAApx;
margin:0 auto;
}
Want a different logo for the smugmug_small style? Change .gallery_234567 to .smugmug_small in the example above and add that to the CSS. etc etc etc.
Want no logo at all in the single image gallery? Add this to the CSS:
.singleImage #myHeader {
display:none;
}
This is the easiest way to do it.
No other background images can be added to the #myHeader layer. If you wanted some other element that would change depending on the gallery or gallery style (etc etc etc) you could add a layer to the #myHeader layer that would have its own class or id and then you'd reference it the same way. This literally makes the cobranding you can do limitless.
Take a look at my page, I've got tons of backgrounds on the page everywhere done just the same way that we're talking about here.
Mike Lane
Sep-06-2005, 02:49 PM
I'll give this a shot. Is it possible to setup a default banner image in the main header, but then override it for specific pages? Rather then explicitly defining one for each gallery?
Absolutely! Just define the #myHeader for the whole site and use .gallery_xxxxxx #myHeader for the specific galleries.
hutch
Sep-06-2005, 07:05 PM
Awesome! Works like a champ! Thanks for the help.:clap
Absolutely! Just define the #myHeader for the whole site and use .gallery_xxxxxx #myHeader for the specific galleries.
vBulletin v3.5.2, Copyright ©2000-2008, Jelsoft Enterprises Ltd.