free hit counters
If you are using Internet Explorer as your browser please be running at least IE 7 or above. This site does not support IE 6 or below. Go here for the latest free version including easy download and installation instructions If you want to make it real easy on yourself, download Firefox , the most popular browser in the world. It's free and simple. You'll be so glad you did.
Jan
7
2009

How to make your header a clickable image map header

Check out the header for ThesisHacker at the top of this page.  Roll over “Thesis Hacker” and “subscribe” with your mouse.  See how they’re clickable?  Read the following tutorial and I’ll explain how this is easily done. A little knowledge of html and css is probably advised and you can go to w3schools to learn more just so you can understand some of the coding going on here.

In my header, “Thesis Hacker” and “subscribe” are images.  So the first thing I did was to make whatever I wanted  clickable, an image.  I uploaded the images to the thesis/custom/images folder on my server.

To create a list of  images in my header, in my custom_functions.php file I added the following code. You can put it anywhere you want but I recommend putting it at the top after the <?php tag. Always describe the function and put it between the comment tags /*  */ at the beginning shown below in green. The comments aren’t shown on your rendered page and it just makes things easier for you to remember…

/*image map header*/
function my_function() { ?>
<div id =”imagemap_header” ><img src=”<?php bloginfo(’template_directory’) ?>/custom/images/thesisheader2.png”  alt=”clickable header” />
<ul>
<li class=”title”>
<a href=”http://www.thesishacker.com/” title=”take me back to the home page”></a>
</li>
<li class=”rssfeed”>
<a href=”http://www.thesishacker.com/?feed=rss2″ title=”Join and learn”></a>
</li>
</ul>
</div>
<?php }
remove_action ( ‘thesis_hook_header’,'thesis_default_header’);
add_action (’thesis_hook_header’, ‘my_function’);

Note a few things here:

I added my header image inside a named div tag

In my function I created an html unordered list and made the separate images a list item.

In your custom.ss file add the following code. You can put it anywhere you want but I recommend putting it at the top. Always describe what you’re doing by putting your descripton between the comment tags /*  */ at the beginning shown below in green. The comments aren’t shown on your rendered page and it just makes things easier for you to remember…

/*image map header styles*/
.custom #imagemap_header {
width: 950px;
height: 190px;
position: relative;
}
.custom #imagemap_header ul {
margin: 0;
padding: 0px;
list-style: none;
}
.custom #imagemap_header .title a {
position: absolute;
width: 493px;
height: 140px;
top: 47px;
left: 235px;
}
.custom #imagemap_header .rssfeed a {
position: absolute;
width: 120px;
height: 33px;
top: 136px;
right: 50px;
}

Note a few things here:

I set the width and height of the div so that it matches the dimensions of the image.  Then I set the position property of the div to relative. This is the key to this technique as it allows the enclosed links to be positioned absolutely, in relation to the edges of the div and therefore, the image itself.

I didn’t want list bullets to display so I removed them by setting the list-style property to none.

I labeled the entire header image where all my images are going to reside as “imagemap_header” and gave it a relative position with a size that I found to work well.

The top and left values mean that the area that is clickable is x amount of pixels from the top and left of the header image itself and in turn surround the actual images I placed inside the header image.

Firebug is essential here and makes life a lot easier instead of trying to guestimate what the top and left values are.

Leaving a comment with code in it...

If you would like to leave a comment and you have examples of code you want to show, you must "escape the code". This allows the entire code to show correctly by inserting certain variable around certain tags to make them show. If you don't "escape the code" your code will show up broken, mangled, and it won't be able to be seen correctly. "Escaping the code" is very simple...

  1. Copy your code you want to show
  2. Click here to go to the site to escape the code
  3. Follow the directions, it's so easy
  4. Once you have the escaped code copied, paste it in the comments area where you want
  5. Now you can enjoy life


Go ahead, leave a comment...

{ 3 comments… read them below or add one }

Steve Heideman April 25, 2009 at 7:31 pm

Thanks so much for the great tutorials! Question for you: Where is the custom_functions.php file located in the thesis theme? I cannot seem to find it??

Keep up the good work!

Reply

faryl April 28, 2009 at 9:43 pm

LOVE your blog!

Thanks for this! I had a bunch of images in a themes header all set to float individually – knew it wasn’t the cleanest way to code that, but figured it was a quick temporary fix.

This is a huge help – thanks!

Reply

Nasty April 29, 2009 at 7:22 pm

Did you get it figured out because I went to your site and I see a header image there

Reply

Leave a Comment

Previous post: How to edit your custom.css, custom_functions.php file and upload it to your server

Next post: How to make a custom box