Randomize the portal logo

This HowTo describes how to randomly load different logos in place of the default Plone logo.

  1. Copy this from plone.css into your ploneCustom.css
    
    #portal-logo {
        background: url(&dtml-portal_url;/&dtml-logoName;) no-repeat;
        border: 0;
        margin: 0.75em 0em 0.75em 1.5em;
        padding: 0;
    }
    
  2. Create this Python script in your custom folder (I named it "logo").
    
    from random import choice
    # logos folder
    logos_folder = "logos"
    # logo names go here
    all_logos = ['logo1.jpg', 'logo2.jpg', 'logo3.jpg']
    # grab a random one
    logo = choice(all_logos)
    return logos_folder + "/" + logo
    
  3. change this line:
    
        background: url(&dtml-portal_url;/&dtml-logoName;) no-repeat;
    
    into this line:
    
        background: url(&dtml-portal_url;/&dtml-logo;) no-repeat;
    
  4. Do NOT mess with this part of plone.css:
    
    #portal-logo a {
    display: block;
    text-decoration: none;
    overflow: hidden;
    border: 0;
    margin: 0;
    padding: 0;
    padding-top: <dtml-var "_[logoName].height">px;
    height: 0px !important;
    height /**/: <dtml-var "_[logoName].height">px;
    width: <dtml-var "_[logoName].width">px;
    cursor: pointer;
    }
    
  5. For my site my logos are larger than the normal plone logo so I had to add in the following lines to my #portal-logo section in ploneCustom.css:
    
        width: 329 px;
        height: 79 px;
        padding-bottom: 20px;
    

Thx to: Robert Hunter, and Chandrakantha Nagaraja

Have fun and if anyone knows why #4 messes everything up, please let me know.

-Paul

Spacing is an issue

Posted by Dan Thomas at Jun 04, 2005 06:08 PM
Thanks for a great how-to.

To make this work, be sure to remove leading spaces if you cut and paste from the ploneCustom.css example above.

Also, while this is probably obvious, you must create a folder called 'logos' and populate it with logo1.jpg, logo2.jpg, etc. The image files you upload do not need to be JPGs. I used GIF images on my site, which are named logo1.jpg etc.

logos folder

Posted by zmz at Jun 05, 2005 03:14 PM
The logos folder needs to be in the plone site directory.

for this to work in plone 2.1

Posted by Winn King at Dec 04, 2005 05:36 PM
since 2.1 autogenerates the id's, you either need to name your images logo1.jpg, etc. before you upload them so that the autogenerated id's match the script, or you need to edit the script to match your image id's after you've uploaded them.