Redesign: Phase 1, more Drupal and the return of CSS site skinning

NOTE: This entry was created in 2005. I'm not using skins on this site anymore, so you can select a different skin, but the code below should work, although a method may be provided to do this with a module now.

This past year I've learned how to do a few things a little better as a site developer. The work I did for Winning Connections and Management Innovation Group sites led me to come up with better ways to architect and improve my markup and style sheet strategy. Working closely with the MIG visual designer also allowed me to come up with better ways for converting a grid-based design to CSS (a topic I'd like to write a lengthier article on later). So I wanted to incorporate some of that learning into this site's design and code. Here's the first set of notes on how I'm starting to evolve this site.

Visual design

The visual design incorporates some of the design elements I used in previous skins a year or two ago. If you've followed my skinning explorations, you might remember those. I like simple, minimal and spare design, but I really react to colors, especially warm ones. I've been looking at the white pages on this weblog every day for the last year and was really missing having warm colors on my screen. So they're back, but, guess what, you can also select a white background too if you're not into the colors.

Here's a comparison of the new skin with some of the site's previous designs:

All were pretty minimal, but the design before this (bottom left in the picture above) was the most spare. I really liked the home page and think that design would have lasted a long time. But I wanted to get a few messages up on the home page -- mainly that I do freelance work now -- so you can see in the screenshots what a big change has occurred in the use of white space. But that design was really a splash page, so I'm comfortable giving up a little on having that quiet page for a little purposefulness.

The version you see live on the site right now is called skin 2. Skin 1 is the white one in the bottom right corner of the picture above. It's the first skin I've had with a background color in a long time. I'm not sure if I'll keep that as the default or use the white one yet. Right now I'm liking the orange background so I'm going to leave that up for a few days and consider setting skin 1 (white background) as the default.

Drupal blocks

I completed the first part of this redesign, creating the new theme files which use blocks more effectively to generate local navigation where necessary. Previously in the non-blog sections, I didn't have any local navigation in areas that needed it, so the back button or the global nav links were the only way to jump back up to a parent. I'm using a PHP snippet in my blocks with a simple array to put out the local nav. I could have done some searching for taxonomy terms to generate that bit, but I wanted a bit more control of the display. The script also searches the URI and if it matches the location in the array, makes the current local nav link appear selected (bold and black). I wish there were an easier way to do that on pages out of the box. I like how WordPress' page model uses parent-child relationships and generates this tree for you.

Now that I know how to use Drupal blocks a little more effectively, I'm really impressed with how much more I can do. I had previously been using the Side Content module (another excellent module, by the way) to output per-page sidebars, but using blocks for entire sections is much more powerful. I'm digging that.

Here's the code I used to generate the local nav in the Services section:

<?php
$dapath
= $_SERVER["REQUEST_URI"];
$MenuArr =
  array(
   
"Overview"=> "/personal/services/overview",
   
"Philosophy" => "/personal/services/philosophy",
   
"Portfolio"=> "/personal/services/portfolio",
   
"Curriculum Vitae"=> "/personal/services/curriculum_vitae"
 
);
$output = "<ul>";
foreach(
$MenuArr as $label=>$link) {
  (
eregi($link,$dapath)) ? $class='class="selected"' : $class=NULL;
 
$link = eregi_replace('\$','',$link);
 
$link = eregi_replace('\*\.\*','',$link);
 
$output .= "<li><a href=\"$link\" $class>$label</a></li>";
}
$output .= "</ul>";
return
$output;
?>

The Publications and Weblog sections also use the Similar Entries module to show "More like this..." type related nodes. I also like the Side Content module, so I have that installed to add sidebar blocks per-node, but I'm not using them anywhere yet.

Drupal front_page.module

I also have the front_page.module working for me. I had actually been using a script I created with adodb to generate the home page because front_page hadn't been created at the time. front_page is another indispensable module if you don't want a cookie-cutter blog, which this site is not. This is one of the reasons Drupal and WordPress are so well-suited as content management systems. The customization options are very good if you know what modules to install.

The PHP Snippets section of the Drupal docs has some great tips for selecting and displaying lists of nodes. Here's the code I used for putting out "New on this site" part of the home page.

<?
$sql = "SELECT node.title, node.nid FROM node WHERE promote='1' ORDER BY node.created DESC LIMIT 10" ;
$output .= "<ul>";
$result = db_query($sql);
while ($anode = db_fetch_object($result)) {
$output .= "<li>".l($anode->title, "node/$anode->nid")."</li>";
}
$output .= "</ul>";
$output .='<div class="more-link"><a href="/drupal-4-7-2/weblog/" class="small">more</a></div>';
print $output;
?>

I learned how to put links from my aggregator into the front page by reading this page on drupal.org: Placing the contents of a block in any location. Here's the PHP snippet I used for the "Elsewhere" content on the home page. This basically tells Drupal to output the aggregator block for category # 6.

<?php
$block
= module_invoke('aggregator', 'block', 'view', 'category-6');
print
$block['content'];
?>

Skins are back!

I've also updated my skinning script to work even though Drupal is caching pages. I did a little workaround by forcing a CSS file to be generated using PHP. That way I can check the cookie to see what the user has set for their skin and use that value in the CSS file rather than in the cached HTML pages Drupal generates.

To force the Apache server to execute a CSS file as PHP, I created an .htaccess file in the directory containing the theme.css file. The .htaccess file contained this text:

<Files theme.css>
SetHandler application/x-httpd-php
ForceType application/x-httpd-php
</Files>

The skinning script works by setting a cookie on your browser with a numeric value. Right now there are only two values, 1 and 2. The theme.css file checks to see what the cookie value is and uses that number to reference the appropriate CSS skin. Here's the PHP code for theme.css:

<?php
header
("Content-type: text/css; charset=UTF-8");

if (
preg_match("/[0-9]/", $_COOKIE["UrlgreyhotSkin"]) ) {
 
$UghSkinVal = strip_tags(trim($_COOKIE["UrlgreyhotSkin"]));
} else {
 
$UghSkinVal = 2;
}

?>

(Thanks to Ed Costello suggesting putting in security measures check in the script above.)

Then you create your skin selecting page, which lists the available skins and has the function for setting the cookie. I won't go into that here, but I use a script I created for doing this that uses some of the PHP from my old skinning script.

More to do

Of course, the remaining part will be to do the minor realignment of the content areas, e.g. the portfolio is moved under the heading "Services" now. Since I've started doing a little freelance in the past year, it seemed like time to make this site a bit more service oriented so I can market what I do. Along with that will be the long needed update of the Lucent Technologies section of my portfolio, which hasn't been updated in 4 years. That will be the biggest part.

Still working on a style sheet for Mac IE 5. Sigh. More to come.

Comments

01 travischristopher
12/02/05 @ 14:46

looking forward to your museings about css grid design, i'm currently doing a bit of thinking about it myself. It's definatly the cutting edge at the moment. Regions in drupal-4.7 should make all this a bit more logical...

02 ed costello
12/02/05 @ 19:16
You will want to add some checks to that code for the UrlgreyhotSkin, at least verify that it's a numeric entity. As written, any value of UrlgreyhotSkin can be injected into your CSS, possibly opening up a cross-site-scripting hole, or at least unexpected, unwanted behaviour.
Advertisement
03 jibbajabba
12/02/05 @ 21:03

I'm not an expert at PHP security, but is this secure enough?

if ( preg_match("/[0-9]/", $_COOKIE["UrlgreyhotSkin"]) ) {
$UghSkinVal = strip_tags(trim($_COOKIE["UrlgreyhotSkin"]));
} else {
$UghSkinVal = '2';
}

print ' @import url('. $UghSkinVal .'/text.css);' . "\n";
print ' @import url('. $UghSkinVal .'/layout.css);' . "\n";

04 Ed Costello
12/03/05 @ 12:02

That should work, alternately if it's always going to be a binary choice, something like:
@$UghSkinVal = 2;@
@if ($_COOKIE["UrlgreyhotSkin"] == 1) {$UghSkinVal =1;}@
print ' @@import url('. $UghSkinVal .'/text.css);' . "\n";
print ' @@import url('. $UghSkinVal .'/layout.css);' . "\n";

Basically, you want to check and validate anything that comes from *outside* your script, especially from a form or cookie.

05 jibbajabba
12/03/05 @ 13:42

Thanks, Ed!

06 Jaza
12/05/05 @ 04:40

jibbajabba said:

bq. Previously in the non-blog sections, I didn't have any local navigation in areas that needed it, so the back button or the global nav links were the only way to jump back up to a parent. I'm using a PHP snippet in my blocks with a simple array to put out the local nav. I could have done some searching for taxonomy terms to generate that bit, but I wanted a bit more control of the display. The script also searches the URI and if it matches the location in the array, makes the current local nav link appear selected (bold and black). I wish there were an easier way to do that on pages out of the box.

If you output a menu block of nav links (generated by the menu module, and some others, e.g. book module), instead of a custom script, the current page will be styled specially as the 'active' menu item. You can see an example of this on almost any page in the "drupal.org":http://drupal.org/ handbooks.

I'm developing a new module, called the "category module":http://drupal.org/node/39683, which merges the functionality of the book and taxonomy modules, and which is designed to make things like generating navigation links much easier and more intuitive. You might be interested to know that I actually looked through some old forum topics on the Drupal web site, when I was trying to piece together the history of the taxonomy module. I found this "thread on the taxonomy idea":http://drupal.org/node/55, which I noticed that you had started and had put a lot of input into!

As one of the big brains behind Drupal's current taxonomy system, I'd be interested to know your thoughts on the "category module idea":http://drupal.org/node/23730, and whether you think it's putting Drupal in the right direction.

Also, re: the new design, very nice! I particularly like the subtle variations in colors and images between sections of the site. But I miss the old front page - that was absolutely stunning.

Jeremy Epstein.

07 jibbajabba
12/05/05 @ 08:51

Thanks, Jeremy.

Yes, I know about using menu blocks, I used menu module in the last version for my "Weblogs" sidebar. But I actually found it quicker for me to just create the block per section I'm using rather than use the menu module.

I look forward to trying your category module. Will it run on 4.6.x? I'm only running stable versions of Drupal. I stopped running CVS versions long ago.

Regarding the last design. I was thinking of making CSS skins for the other three screens you see on that picture above. So you might see that one back yet.

08 chx
06/11/06 @ 05:13

where you list node titles, I think you'd be better with node_title_list().

09 E. Gawater
02/11/07 @ 21:18

is there anything that css cant accomplish ;) nice post

10 NikkiJ
05/15/07 @ 10:44

I'm really impressed with your work, well done and I look forward to seeing more from you

Advertisement
11 dizi izle
12/18/07 @ 13:04

it gives an error for me

12 jibbajabba
12/19/07 @ 10:52

Yeah, this post is over 2 years old, dizi izie. I removed the site skinning feature, but the code above should still work.

13 Kadir
01/09/08 @ 13:04

nice designs thanks for your efforts

It's really amazing how much information you can find if you target your search.
You have just a great bunch of information. I thin I can compliment your site. Stop by and take a look. thanks Matty

http://nicheplace.blogspot.com

15 Charity cds
01/20/08 @ 07:40

Great code guys - you're just making my life simpler all the time.

16 Sammie
02/04/08 @ 10:15

Do you do custom work? I am looking for someone to design a custom blog for me and possibly a complete redesign of my website.

Sammie
www.SammiesTanning.com

17 jibbajabba
02/04/08 @ 10:33

Sammie, I am not doing freelance or consulting right now.

18 Anonymous
02/09/08 @ 15:31

Thanks for the helpful info.

19 mdouble
02/20/08 @ 23:57

I'm an internet marketer, writer, graphic artist and photographer. I really appreciate good design work and simply had to comment about this site. To be short and sweet, the site is simply a pleasure to read, from the header right down to the comments. Very nicely laid out, easy to read and visually strong. Nice design, cool graphics and simply well done.

20 Ramses
03/02/08 @ 17:43

I actually found it quick for me to just create the blocks per sections I am using rather than use this the menu module.

21 DLN
03/06/08 @ 17:49

For a fledgling web designer like myself, It is amazing to see just how much the Web has grown in it’s capacity for true expression of the designer. Coming from a graphics background, it used to be frustrating to try and implement a design idea for a web page. This was due to the fact that there was no way to do it. I actually got to the point where I lost interest.

Fortunately, things have changed, and are changing dramatically, and web design is becoming incredibly fun. The limitations are becoming less and less. Great inspiration from your site!

22 Phong Chieng
03/10/08 @ 17:15

Every time I read stories about how great drupal is, I feel bad for having chosen Wordpress for my blog..

23 Pete
03/19/08 @ 12:02

Are you planning on selling any of your designs?

24 jibbajabba
03/19/08 @ 14:49

Pete: I was thinking about it and bought a domain with that purpose in mind. But I ended up getting too busy with work to get around to it. I have other projects that I have more of an interest in at the moment.

25 dizi izle
03/20/08 @ 10:22

Thanks for the helpful info...

26 estetik
04/02/08 @ 08:33

Very useful info for me. Thanks a lot.

27 pagerank links
04/26/08 @ 00:55

I've been trying to learn a lot more on CSS myself. You've got some good information here, thanks much for sharing and good luck with your learning!

28 Webmaster
04/30/08 @ 14:31

Some really great looking designs, I like this new one best though.

29 James Henry
05/05/08 @ 02:29

Very helpful information and incredible designs. Thanks

30 Phim
05/06/08 @ 15:58

Old topic but the code still works and very impressive design.

Thank you

31 Chris
05/22/08 @ 18:08

Very nice design and great tutorial ;)