Skip to main content

Theme function

Field Type Suggestions in Drupal 7

Today I finally got around to testing out the new field suggestions in Drupal 7. If you’re not familiar with the standard suggestions in short you can either use field templates or override theme_field using a naming convention not unlike we do with preprocess functions. What struck me as kind of odd was the lack suggestions for field types—maybe there’s a very good reason for this such as performance, I don’t know, but I thought it might be interesting to see if I could use them, if I wanted to.

Add first and last classes to secondary local tasks

We had a project recently where we needed to add first and last classes to Drupals secondary local tasks. I was in a bit of a hurry so instead of trying to figure this out myself I Googled it and pretty quickly found this post on Drupal.org which seemed to fit the bill. Problem is the post doesn’t actually tell you how or where to use the snippet, which isn’t much good for those of you struggling with Drupal in the first place. Never fear, I’ll show you how to get those handy first/last classes into Drupals secondary local tasks.

Page template suggestions for taxonomy vocabs

Drupal’s template suggestions are plentiful and pretty powerful stuff, however, given all the options there are some noteable oversights. In particular the ability to use page-taxonomy suggestions per vocabulary, something like page-vocab-1.tpl.php to theme all taxonomy term pages in vocabulary 1 (where 1 is the VID or vocabulary id).

To achieve this we turn to our trusty preprocess_page function which by now every Drupal themer worth his or her salt knows all about.

Give your Nodes some Class

In this short tutorial I’m going to show you how to set a unique class on your nodes based on taxonomy terms, which is something I’ve been asked about more than once or twice.

Load Unlimited Stylesheets in IE7

What a bane of the theme developers life, IE’s inability to load more than 30 linked stylesheets. This is a huge pita and forces you to either turn off modules or manually aggregate your themes stylesheets, such as how the Genesis theme does with its option to use an “all-in-one.css” stylesheet as a workaround.

Setting Blocktheme Classes with subtheme_preprocess_block

I’ve become a big fan of the fantastic Blocktheme module. Up until now I’ve followed the README instructions and either built blocktheme templates or just printed the $blocktheme variable in my block.tpl.php and block-xxx.tpl.php templates.

Thats all well and good, but in my current project I wanted to be able to theme blockthemes by region. The main reason for this is we are making just very minor changes to the block styles depending on the region and we see no point in creating additional blockthemes.

Using hook_theme to modify Drupal forms

I’m going to show you how to use hook_theme to make some commonly requested changes to the Search form and the Comments form in Drupal 6. We’re also going to learn how this is done in your Genesis subtheme and the normal way of doing things. Take it as read the that the Genesis method also works for Zen sub-themes since the implementation of hook_theme for subthemes is the same.

Add <span> tags to Primary links for Sliding Door Tabs

In the upcoming series of Genesis video tutorials I will be presenting a segment on how to build sliding door tabs for Drupal’s Primary links.

As you may know to get the full hover effect working in Microsoft’s venerable Internet Explorer web browser we need to wrap the anchor text in <span> tags, since IE does not support the :hover pseudo class on anything but an anchor, bless its little heart.

Now, the standard Drupal “fix” for this is to override the theme_links function. I’ll detail that here, but first I want to explore another idea I hit on recently - using jQuery to get the job done.

Change the XML or Feed icons with theme_xml_icon & theme_feed_icon

Here in the first of our series on over riding theme function we attack theme_xml_icon.

As you will read on the Drupal API page the function has largely been superseded by theme_feed_icon. Therefore it makes sense to look at both and kill two birds with one stone. They’re very similar with only minor differences in their respective output.

So to the code - first lest take a look at the default functions.