Twitter: walking down freshman hill... haven't done this in a lonnng time.
Subscribe via RSS or email  #error


Customizing K2: Part 4

Apr 16, 2006 in , , ,

I didn’t think I could talk this much about K2, but over the course of my recent redesign a few things have come to mind that I’d love to share with everyone. This whole K2 customization series has become rather lengthy, so I am really considering making a stylized PDF with them all and adding to each a bit. There might even be a Part 5, so leave comments if you want me to include something.

The Sidebar Main Menu

I’ve been using the standard horizontal menu that comes with K2 for several months. It works great, but it just says “I am using a default K2 install.” If you’re looking for an alternative design and want to get your blog to look much more unique, a sidebar menu may be the way to go. Here’s the break down of how this customization works: snag the menu code from header.php, paste it at the top of sidebar.php, add lots of CSS, enjoy.

Open up header.php and find the following code snippet and cut it out. Save header.php.

<ul class="menu">
    <li class="<?php if (((is_home()) && !(is_paged())) or (is_archive()) or (is_single()) or (is_paged()) or (is_search())) { ?>current_page_item< ?php } else { ?>page_item< ?php } ?>"><a href="<?php echo get_settings('home'); ?>">Weblog</a></li>
    <?php wp_list_pages('sort_column=menu_order&depth=1&title_li='); ?>
    <?php wp_register(’<li>',''); ?>
  </ul>

Edit sidebar.php so that the top of your file looks like the code below. Notice how I changed the ul class to sbmenu. This was purely aesthetic but naming it like this is good coding style, with the sb prefix denoting sidebar usage.

<hr />
<div class="secondary">
<!–/* MAIN MENU START */–>
<ul class="sbmenu">
    <li class="<?php if (((is_home()) && !(is_paged())) or (is_archive()) or (is_single()) or (is_paged()) or (is_search())) { ?>current_page_item< ?php } else { ?>page_item< ?php } ?>"><a href=”<?php echo get_settings('home'); ?>">Weblog</a></li>
    <?php wp_list_pages('sort_column=menu_order&depth=1&title_li='); ?>
    <?php wp_register('<li>',''); ?>
  </ul>
<!–/* MAIN MENU END */–>

If you are going to paste this code into your blog, be weary of foreign characters that may appear due to the way I have it displayed. Always double check what you paste.

Sidebar Main Menu CSS

The way I chose to style my sidebar menu includes a hover activity over the entire span of the link. If you would like to use a background image for the menu items, add the appropriate url for the backgrounds of ul.sbmenu li.current_page_item and ul.sbmenu li:hover. I also probably overused !important and should revisit the rules. Note: I haven’t tweaked this code for IE.

/* Sidebar Menu */
ul.sbmenu{
   padding-top: 5px;
   margin-top: -34px; /* Moves the menu up into the header image */
   margin-left: 0px !important;
   }
ul.sbmenu li{
   display: block;
   line-height: 1.1em;
   margin-left: -10px !important;
   padding-left: 10px;
   }
ul.sbmenu li:hover{
   background: #d5d5d5 !important;
   width: 216px;
   margin-left: 0px;
   }
ul.sbmenu li a {
   font: 2em Helvetica, Verdana, Arial, Sans-Serif;
   text-transform: lowercase;
   color: #666;
   width: 216px !important;
   display: block;
   margin: 0;
   border: 0;
   }
ul.sbmenu li a:hover{
   background: none !important;
   text-decoration: none !important;
   color: #000;
   }
ul.sbmenu li.current_page_item a,
ul.sbmenu li.current_page_item a:hover {
   color: #333 !important;
   background: none !important;
   text-decoration: none;
   }
ul.sbmenu li.current_page_item{
   background: #CCC !important;
   width: 216px;
   margin-left: 0px;
   }

Hopefully you should now have a slick, vertical sidebar menu on your blog. Enjoy it now, because I’m telling you this will be the trend for Web 3.0, vertical sidebar menus.

The 3 Column K2 Layout

Sidebar space is a valuable commodity these days. There is always something great to put in your sidebar whether it be your recent coComments, del.icio.us, ma.gnolia or digg bookmarks, current flickr photos, tag cloud, creative commons license or lengthy blogroll. Three column layouts afford bloggers to give their readers more content and more reasons to stick around and hopefully subscribe to your website. Take a look at some successful three column layouts: Pat Collins’ LeftLane.org and Bharath Kumar’s OBharath.net. When it comes to coding the principle is very simple; just widen up the secondary div and put two divs inside of it, one floated left and one floated right. Then you have the task of deciding what you want to put in each sidebar and sort that out in sidebar.php. However, implementing a successful three column layout will require a wider page, something like 800 pixels and higher. I highly suggest taking a look at Bharath’s code in the 3 Column K2 style he has released.

We will be looking at setting up the necessary div containers first. Open up sidebar.php in your favorite text editor. Find one of the first lines at the top that says <div class=”secondary”> and place the line below directly under it.

<div class="leftsidebar">

Now you have the task of sorting out what you want to go in the 1st sidebar and the 2nd sidebar. The best thing is to add things and see what looks best. Once you have filled out the left sidebar, close it off with a </div>. Then add the next line right after that closing div.

<div class="rightsidebar">

Repeat what you did earlier and fill up that div with items you would like to populate the third column. Upon completing that, close it off with </div>. Now that we have the basic php structure down, it is time to style the rightsidebar and leftsidebar classes in CSS.

/* This code assumes you have a wide #page and a narrow .primary */
/* look at Bharath’s CSS for a better idea */
.secondary {width: 450px !important;padding: 0px 0 10px!important;margin: 0 0 20px 500px !important;}
.leftsidebar {
   width: 200px !important; /* adjust widths as you see fit */
   _width: 200px; /* http://getfirefox.com */
   float: left !important; /* make this column stick to the left of the secondary div */
   padding: 0 5px 0 10px !important; /* padding: top-right-down-left */
   margin: 0;
}
.rightsidebar {
   width: 200px !important;
   _width: 200px;
   float: right !important;
   padding: 0 10px 0 5px !important;
   margin: 0;
}

If you want to make the columns more distinguishable try adding a left and right border to .leftsidebar. This gives you a general idea of how a 3 column K2 style can be formulated. This CSS was purely for a guideline and probably won’t look all that good in real life.

Saving Bandwidth with Image Maps

The footer is a great and unobtrusive place to show off some icons of affiliations, memberships or other websites you support. However, it starts to become detrimental to your site’s loading time when you have several images loading in your footer or any image in general. The concepts I am about to discuss can be used on any image, not just the footer. Assuming your footer already has an image, open it up in photoshop and place your icons where you want them to be.

Photoshop Image Maps

Select the slice tool, the one to the right of the crop tool. Slice out each area that you want to be clickable, then right click that area and select Edit Slice Options. This displays the exact location of the image map which we can use for the CSS.

Photoshop Image Maps

Before we can create a CSS selector to control the location of the image map, we need to create a class in the footer with the appropriate link. Now that the footer doesn’t hold any text and everything is in the image, I changed <p id=”footer”></p> in footer.php to <div id=”footer”></div>. Excluding my feedburner and creative commons code, this is what my footer.php looks like.

   <br class="clear" />
</div>
<hr />
<div id="footer">
   <a href="http://barcamp.org/BarCampHouston" class="barcamp">BarCamp Houston</a>
   <a href="http://mediatemple.net/.from/paulstamatiou.com" class="mediatemple">Media Temple: High Velocity Web Hosting</a>
   <a href="http://gatech.edu" class="gatech">Georgia Tech</a>
   <a href="http://9rules.com" class="ninerules">9rules Network</a>
</div>
<?php ?>
   <?php do_action('wp_footer'); ?>
</body>
</html>

Notice how each link I included has a class - eg barcamp, mediatemple, gatech and ninerules. I will take these classes and directly target their hyperlink attributes with the CSS like the snippet seen below.

#footer a:link, #footer a:visited { text-decoration: none; border: none; }
/* line above ensures that footer hyperlinks are not underlined */
a.barcamp {
   position: absolute;
   display: block;
   text-indent: -9999px; /* moves link text off-screen */
   background: transparent;
   left: 534px; /* taken from Photoshop slice info “X” */
   top: 10px; /* taken from Photoshop slice info “Y” */
   width: 175px; /* taken from Photoshop slice info “W” */
   height: 48px; /* taken from Photoshop slice info “H” */
   cursor: pointer;
   border: 0px;
}

For this code to work, it is assumed that you already have a footer image defined in your footer div. If not, get on that using the CSS below as an example. You will have to change the height, width, background and margin accordingly.

#footer {
   background: #5A5A5A url(’defiance/xlfooter.jpg’) no-repeat !important;
   height: 71px;
   margin: -25px auto 0 !important;
   position: relative !important;
   padding-top: 0px;
   width: 900px;
   border: 0px !important;
}

Repeat the action of slicing up an image map area and creating the appropriate CSS for it using a hyperlink class defined in footer.php. Be sure to delete all of the slices before saving your footer image or Photoshop will cut it up and save it in multiple images, which is not what you want. Also when determining clickable image map areas in Photoshop, try not to overlap areas as you might confuse the browser with conflicting image maps. At the time of this writing, these image maps appear to work fine in IE, Safari, Firefox and Konqueror.

Promote this article on various sites or email to your friends:     



36 Comments

  1. Thanks for the 4th and follow up article to the rest. I love K2 and I like to customize but I wasn’t sure on some of this.

    Especially image maps.

  2. Seems like she already covered it pretty well…

  3. Hey Paul, Great job on the new layout. I like it a lot! Keep up the good work.
    Joe

  4. Nice stuff Paul, I was hoping you’d be giving another K2 tutorial, this is great, they’ve all really helped me in my design.

  5. how did you do the numbered comments?

  6. Paul, as always thanks for your work you do here, I use it constantly to learn what I can about web design, macs and mint (all things I really enjoy). I had a question for you if you get a moment, about I used your CSS to move the menu links into a vertical setup, but when you have the mouse over the image in the header the “block” part of the menu flickers and flashes. Is there a way to limit it to only that area that its in? Also because I did it this way, will I be able to make the header clickable (I have the coding from your other tutorials on how to do it). thanks for your help.

  7. Thanks for writing that part about image maps. I’ll be using that on my next design.

  8. I wrote a simple tutorial on how to add in two lines of PHP and some CSS to get the top 15 tag bars seen in binarybonsai’s archives in place of the usual tag cloud. It’s my first tutorial, so please be gentle with me! Hope it’s of use.

  9. A few things you might want to talk about perhaps?

    1. Embedding Adsense ads into your blog at specific places in K2. I do this on my own blog with CG-Inbetween and Adsense

    2. Cross-posting WP posts to other sites like LJ, MySpace, etc. The biggest problem with xposting right now seems to be that in K2 images get handled by the CSS but there needs to be different info in the IMG SRC tags when cross-posting since other sites cant use your CSS

    3. Perhaps provide an easy way for people to link a blog entry to one of the online news sites like Digg, etc?

  10. Awesome tutorial, thanks for the service.

  11. This tutorial rocks. I used the part about the image map for the first time on a site I recently coded for Chris Gillis on http://bieredetable.com/.

    He’s a graphic designer and made all the graphics, I did all the code to plug in the design to k2. Using an image map for the header title image made things much easier.

  12. Thanks for this one. I’m not sure what I learned but I’m sure I learned something. I use sidebar widgets for the sidebar so I didn’t need the code for the menu.
    And aesthetically I’m happy with the one sidebar so I didn’t need to use the double sidebar option.
    Image maps, I’m afraid I still don’t know what they are or how one or more would benefit me. Something to read up on there. Although generally I’m trying to avoid using any more images on my side as I want to keep it fit and slim and moving fast.
    Generally, I suppose, I felt that this tutorial moved on a long way, esoterically, from the first three. Suddenly it wasn’t for beginners any more and seemed to be speaking to people who already knew a whole lot more than me.
    Not that it wasn’t useful, only that it wasn’t perhaps as useful as the first three seemed to be.
    Still, tomorrow I’ll move on to tutorial five. Will I understand it?

  13. I have the sidebar menu setup and working properly. I like the look of having the pages listed in 2 columns, like how yours is currently displaying. How did you make that happen? and what css file should I make changes to? -Thanks!

  14. Hi, I used your helpful toutorial to move the pages to the sidebar, but I can’t seem to get the links to appear at any time except when I’m in the categories section. can you help?

  15. Hi,
    I really want to use your image map ideas for the header, but it seems editing the header in such a way is a bit more complicated. Or so it seems to me :)

    How would I use an image map in the header?

  16. Thank you so much for the information on mapping the footer. I was able to use it to map my header logo. There might have been an easier way, but this worked for me. Thanks, you are a Godsend! :-)

    Nicole

  17. Thanks for your advice! I’m now using K2 release 4.

  18. Hi. I’ve been designing Blogger Blogs for a while, and I have just started working on wordpress. Is there a way to add a second sidebar to K2 in Wordpress.com hosted blogs where you can only edit the CSS?

    If not, which standard theme would you recommend as an easily customizable 3 column theme?

  19. @Sarah - I’m not sure if it’s still on WP.com but you can use my “2813″ theme

  1. [...] Customizing K2: Part 4 Published April 17th, 2006 Tags: Asides, blogging, k2, themes, Wordpress. Customizing K2: Part 4 is the latest in a series of articles by Paul Stamatiou explaining how to customize the excellent Wordpress theme K2. Well worth the read if you are looking to theme Wordpress. (0) [...]

  2. [...] Paul Stamatiou has released Part 4 of his excellent K2 customization series. Along with his high quality stuff, he walked through the basics of How-To acheive the 3 Column layout. If you havent seen his HOW-To’s, I request all K2 users to have a look at those other three parts of his customization series. [...]

  3. Modificando K2, template para Wordpress (cuarta parte)…

    Cuarta parte de la serie de tutoriales que Paul Stamatiou ha realizado sobre como modificar K2, popular template para Wordpress. (en ínglés)…

  4. Modificando K2, template para Wordpress (cuarta parte)…

    Cuarta parte de la serie de tutoriales que Paul Stamatiou ha realizado sobre como modificar K2, popular template para Wordpress. (en ngls)…

  5. [...] Part 4 talks about K2 sidebars, 3-column layouts and image maps, while Part 5 concerns load time optimization. Although Part 4 is very much crafted for K2 themes alone, but you could actually use the advice given in Part 5 for other blog themes as well. In fact, I’ve used a couple of his optimization tips on some of my blogs as well, e.g. CSS compression through CSS Tweak and turning off advanced functions that require extensive Javascript. [...]

  6. [...] for K2 : k2 mod part 1 k2 mod part 2 k2 mod part 3 k2 mod part 4 k2 mod part 5 [...]

  7. [...] He emailed me a photoshop mockup of exactly how he wanted his beer blog to look. I cut it up a little on my computer, separating the different graphical elements in order to plug them into the theme. I made the title graphic clickable by using an image map technique I learned from Paul Stamatiou’s tutorial. All in all, I think the end result is very nice. The purpose for his blog compliments K2’s abilities very well and I think he will have a lot of fun writing about his passion on his brand new blog. [...]

  8. [...] It appears that there are TWO three-column remixes of k2 - the other one, “3k2″, has working widget support, although it has flanking sidebars, which I dislike. Checking it out now…. here is a comparison with the other, Bharath’s 3-column k2, which is slightly slicker and more professional, and I’ve been checking out, but lacks the working widgets. Of course, all this is just CSS - someone wrote up notes on adding a second sidebar to the latest k2 manually, with code examples. Of course, I’d prefer a centrally maintained and undated solution…. [...]

  9. [...] K2 Customization - Part 1 - Paul Stamatiou.com K2 Customization - Part 2 - Paul Stamatiou.com K2 Customization - Part 3 - Paul Stamatiou.com K2 Customization - Part 4 - Paul Stamatiou.com K2 Customization - Part 5 - Paul Stamatiou.com Share This Post:These icons link to social bookmarking sites where readers can share and discover new web pages. [...]

  10. [...] ( Part 1, 2, 3, 4, 5) Feed for this Entry Trackback Address [...]

  11. [...] 利用Image Map减少meta部分的image读取量: 这个在Paul的网站上有详细的叙述。把一些常用的meta部分的image用一个大的image来代替,并且在css文件中设置为背景。然后利用div的控制实现鼠标的悬停指向。 Post by SUN @ 7:10 am 与时俱进 | [...]

  12. [...] Three Column K2 Mod for WordPress Customizing K2 @ http://paulstamatiou.com/: Part 1 Part 2 Part 3 Part 4 Part [...]

  13. [...] 利用Image Map减少meta部分的image读取量: 这个在Paul的网站上有详细的叙述。把一些常用的meta部分的image用一个大的image来代替,并且在css文件中设置为背景。然后利用div的控制实现鼠标的悬停指向。 这里以我siderbar下方的meta图标为例。我使用的Two Columns的模版,因此,除了index.php文件外,还会有一个siderbar.php文件,meta信息都会放在这个文件中。一般我们在 meta部分会添加不少图标,所以我们可以截图后粘贴到photoshop,然后利用Slice Tools对图片进行分割,分割完成可在每个Slice上右击鼠标,读取Slice的属性,记下 下图中的X,Y,W,H坐标值。 接着建立了一个menu_meta: [...]

  14. [...] 利用Image Map减少meta部分的image读取量:这个在Paul的网站上有详细的叙述。把一些常用的meta部分的image用一个大的image来代替,并且在css文件中设置为背景。然后利用div的控制实现鼠标的悬停指向。这里以我siderbar下方的meta图标为例。我使用的Two Columns的模版,因此,除了index.php文件外,还会有一个siderbar.php文件,meta信息都会放在这个文件中。一般我们在 meta部分会添加不少图标,所以我们可以截图后粘贴到photoshop,然后利用Slice Tools对图片进行分割,分割完成可在每个Slice上右击鼠标,读取Slice的属性,记下 下图中的X,Y,W,H坐标值。 Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages. [...]

  15. [...] you can reduce the number of HTTP requests with image maps. I discussed that in more depth at the end of this article. If you are using K2, you can get rid on one extra HTTP request by using one stylesheet, style.css, [...]

  16. [...] 利用Image Map减少meta部分的image读取量: 这个在Paul的网站上有详细的叙述。把一些常用的meta部分的image用一个大的image来代替,并且在css文件中设置为背景。然后利用div的控制实现鼠标的悬停指向。 这里以我siderbar下方的meta图标为例。我使用的Two Columns的模版,因此,除了index.php文件外,还会有一个siderbar.php文件,meta信息都会放在这个文件中。一般我们在 meta部分会添加不少图标,所以我们可以截图后粘贴到photoshop,然后利用Slice Tools对图片进行分割,分割完成可在每个Slice上右击鼠标,读取Slice的属性,记下 下图中的X,Y,W,H坐标值。 接着建立了一个menu_meta: [...]

Post a comment, receive Stammy points.


Send a trackback.


  • If you plan on posting code, run it through Postable first.
Copyright © 2005 - 2008 PaulStamatiou.com  Privacy Policy - Terms of Service Can't spell my name? Use PSTAM.com. Go back up ↑.