Drupal Theming

Redesigning Lhmdesign

So, long-story-short, I've decided it's time to give the whole Lhmdesign site, including this blog, a redesign. It's been about a year now since the current design went live and, well, you know what designers are like - fiddlers!

Anyway, as this blog is written for you, I'd like to get your input on what features etc. you think should stay/go/be introduced in the redesign.

Currently, I'm thinking:

Staying

  • Most recent posts block
  • RSS subscription options

Going

  • Random tags cloud block
  • Sponsors block

New Stuff

  • Most popular posts block
  • Top commenters block
  • Subscribe via e-mail option
  • Recommended block
  • Categories block/page

Any thoughts?

Classes For (Almost) Everything In A Drupal Theme

Thanks to the Zen theme there is an awesome bit of code available to Drupal themers which enables the addition of dynamic classes to your body tag based upon a number of different parameters, such as your position and status within a site, like so:

Drupal theme body classes

As you can imagine, this is incredibly useful for Drupal theming, as it provides a set of classes on the body which then allow a simple way to target specific areas of a theme via CSS.

I used to end up writing lots of different bits of code into a theme file to achieve this functionality, but the Zen theme does a great job of wrapping it all up in one bundle, and also nicely comments the code so that you can figure out what's happening :)

How to use the code:

Implementing the code into your own theme is a simple two step process:

  • Step 1.
    Copy the main chunk of code into your template.php file
  • Step 2.
    Edit your theme's page.tpl.php file to add the body classes

Step 1
The main chunk of code you will need lives in the Zen theme's ZENtemplate.php file.

I have edited it slightly to remove any Zen theme specific code (such as references to Zen theme sub-themes).

Copy all of this code (except the opening and closing php tags) and paste it into your theme's template.php file.

(Just be aware that if your theme's template.php file already contains a _phptemplate_variables() function you will need to integrate the new code with your existing code, as you cannot re-declare the same function. Unfortunately, it's difficult to give a more detailed explanation about how to do this as each situation will be different.)

Overriding Drupal's Default RSS Feed Icon

By default, a number of Drupal themes (including Garland) output an RSS feed icon Feed icon at the bottom of pages which generate a feed. The feed icon is generated because of the existence of the following code in the page.tpl.php file

<?php print $feed_icons ?>

But what if you want a different looking icon? Maybe something larger, or a different color?

Well, there are a couple of ways to achieve this:

  • The not-so right way
  • The right way

1. The not-so right way

Drupal's default RSS feed icon image is located in your site's folder structure at 'misc/feed.png'. The not-so right way to change it is to simply swap this feed.png image for another feed icon image (just making sure to also name the new image feed.png).

This method will work, but is not recommended. The reason being, that you are effectively overwriting a core file. When you do an upgrade of Drupal, your new feed.png image will be replaced with the original feed.png image and you will need to update it again. This is clearly not a good idea if you have lots of sites or are doing sites for clients who do not know how to do such updates, and ultimately it's just an all round messy solution.

So, a far better solution would be one where we do not alter any core stuff, and the new feed icon remains in place even after an upgrade...this is the right way.

2. The right way

The first thing we need to do is find out what function Drupal is using to output the feed icon. So, go over to Drupal API, and do a search for feed_icon. The search should return one result - theme_feed_icon. This is exactly what we're after. Anytime you see the word 'theme_' at the beginning of a function it means that we can override the function - which is what we want to do in this case.

Theme Template Files in Drupal 6.0

I've just heard about an upcoming Drupal Dojo lesson which joshk is doing on Drupal 6 theming - entitled Dojo Lesson #41: Theme Template Files in Drupal 6.0.

This is definitely worth checking out. The dojo lessons are always informative, and if you can't be there live they're pretty good at providing the screencast for you to watch later on.

Drupal Themes On eBay

Hi everyone.

Firstly, a Happy New Year etc. Work got a bit hectic over the Christmas period which resulted in the lack of posts recently, but I'm gradually cranking back into action.

Anyway, whilst doing a little holiday shopping last month I came across one of the several listings on eBay for Drupal themes. Naturally I had to take a closer look. Imagine my 'surprise' when I found out that this was in fact just a bundle of freely available themes.

I particularly like the part in the ad copy which says:

"They have taken us years to find and explore for quality to save you time and money" - really? Years?

There then follows a 'handy' explanation about how to install and enable your theme, which is written entirely in black font on a black background, and also contains out of date information - nice.

And just to finish off:

"These templates are FREE" - except, of course, when you buy them from this listing - oh dear.

Best to not even get started on the eBay Drupal ebook sellers ;)

Update: Dreamweaver CS3 Extension For Drupal Theming

Around three months ago I wrote about a Dreamweaver CS3 extension for Drupal theming which was being developed by Peter Apokotos, and about which a discussion was happening at the time on the themes mailing list. In the meantime another extension has been discussed on the mailing list, as well as on drupal.org, this time being developed by Sherif Mayika.

The two projects are currently completely separate. According to Sherif, his extension will have support for versions 4,5, and 6 of Drupal and is soon to reach beta. I contacted Peter about the progress of his extension and he told me that 'we have a working extension with just about everything but the kitchen sink in it.' So it looks like Drupal theming is going to be getting some Dreamweaver extension love anytime soon.

One thing that, as far as I'm aware, neither Sherif nor Peter have confirmed yet is whether the extensions will be free or not.

5 Things Drupal Could Learn From WordPress About Themes

OK, so before everyone starts sharpening their knives I would like to make a couple of points:

  • I am not a closet WordPress fanboy ;) I have just been playing around with WordPress theming a bit lately, and these are some (hopefully) fairly objective observations.
  • Drupal is in competition with WordPress. If Drupal can learn from WordPress in areas where WordPress is superior, and improve upon and surpass WordPress in those areas, ultimately it will help Drupal kick some WordPress butt.

All that said, here goes:

1. Pictures sell

Start by looking at the main theme download page on WordPress and compare it to Drupal's main theme download page.

Drupal and WordPress main themes pages

Which one of those do you think looks more inviting to a designer trying to decide where they should spend their time, or a new user looking to develop their first site?

Adding A Class To A Drupal Theme For Logged In Users

I was working on a Drupal theme recently which required a number of different elements to be present on a number of different pages, but only for logged in users.

Using a little PHP I was able to add a class of 'in' to the body which would only appear in the html when a user was logged in.

To do this, just find the opening <body> tag in your page.tpl.php file, and add in the code below.

<body<?php global $user; ?><?php if ($user->uid): ?> class="in"<?php endif; ?>>

Then, you'll be able to write a general rule for logged out users, such as:

body {
background: #fff;
}

And a more specific rule for logged in users, such as:

body.in {
background: #000;
}

Drupal Themes On Mashable + Drupal Dojo

Bit of a Sunday round-up today.

Firstly, Mashable has had a couple of 'interesting' Drupal theme related posts in the past month:

I generally like Mashable as a site, but am not too sure about the editorial quality when you get guys from Mashable like Adam Hirsch saying things like
'I don't know if you guys heard but there are rumors/talks of the fact that Drupal is going to have new functions that easily integrate with WordPress and Facebook'

Facebook yes, but WordPress - wtf?

Secondly, I just finished watching MerlinOfChaos's 'What's New In Drupal 6 Theming?' Drupal Dojo presentation. As ever, it's quality stuff from the Dojo and well worth a look.

Drupal Form Theming Quick Tip

Very quickly, here's a useful tip if you're theming any kind of Drupal form. Just put the following in your overriding .tpl.php file

<?php print "<pre>"; print_r(array_values($form));print "</pre>"; ?>

and it'll output a complete list of things you can theme.
Not ground breaking I know, but one of those things I can never seem to find when I want!