Skip to main content

Drupal snippet

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.

Add Superfish Drop Menus to Any Theme, Easily

How to add a Superfish drop menu to Genesis or Adaptivetheme is one of the most common questions I get. Believe when I say I get emails from well intentioned Drupal users on a weekly basis asking me this. So now, please stop emailing me, I relent, heres how its done.

Gpanels: Create a two column section for blocks with Gpanels and Adaptivetheme

Gpanels are easy to use PHP and HTML snippets for creating multi column layouts. The idea is you copy/paste them into page.tpl.php (where ever you want) and place blocks into the regions to create columns of blocks.

Gpanels come with both Adaptivetheme and the Genesis starter theme.

This video walks you through the process of adding a Gpanel, enabling the regions and CSS, and then placing the blocks in the newly available regions.

You can learn more about the themes that use Gpanels for Drupal.org or our website:

http://drupal.org/project/adaptivetheme

How to Add unique classes to Drupal menus

Sometimes you want to be able to style menu items individually. For example you may want to use image replacement to display icons instead of the text, or you may want to make one menu item stand out from the rest.

Drupals Primary and Secondary links allow you to do this because they print a class on the li that includes the mlid, so its easy to target a particular link doing something like:

li.menu-123 a {font-weight: bold;}

But, in normal Drupal menus, the ones that appear in blocks, no such classes appear, which leaves them all with the same style.

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.

How Gpanels Work - the Secret Sauce

When I first built Gpanels I ran into the usual layout problems when using percentages—IE rounding up, Operas inane percentage rounding behavior and a bunch of other pita issues.

I decided there must be a better way of achieving the layout I was looking for, and not using grids, because my base theme is not grids based.

Gpanels Busted for Illegal Steriod Use, but OMG what a Performance!

As promised today we roll out the all new Gpanels - nine in total, five more than the original four released in Genesis. These will be released in AdaptiveTheme RC4 shortly and will be included in the next version of Genesis as well.

CSS Sprites for Drupal Themes

What is a CSS sprite? In short a CSS sprite is one big image combining all the images used in a theme or web site template. So instead of having loads of separate little images, you combine them into one.

For an example Yelvington posted a really good example of CSS Sprites - take a look at his example sprite.