Tutorials

Displaying Hierarchical Content

Published February 19, 2009

This article is also available in French . Displaying hierarchical content is a common request of database-driven web sites. Drupal gives you great flexibility in doing this without writing a single line of code, using a couple of battle-tested modules. As an example, let's say you're building an automotive web site. Your site is going to have a list of automotive brands and the vehicles they build. You'd like to only have to enter each brand's information into the database once, then simply refer to that brand whenever you add one of their vehicles to the site. In this example, I have 2 brands, Chevy and Jeep, and each brand has 3 vehicles. Drupal's powerful CCK module allows you to define different content types for your web site. The Node Reference module, included with the rest of CCK, allows you to set up hierarchical relationships between content types.

Using Display Attachments to Provide a Consistent Summary in Views 2

Published February 13, 2009

The "summary" list is Views is a really handy feature, but unless it is properly configured, it can lead to an inconsistent experience for end-users. The goal of this post is to demonstrate how a little bit of configuration can provide a very consistent user experience. Here's a quick example of what I'm trying to avoid: consider the following content type called, "Food": As you can see, it is a very simple content type, with only a single added field, "field_food_type". This text field is set up to require the user to select one of its options. When creating a view to show all "Food" nodes, there might be too many to display all at once - you'd like to break up the view by food type in order to allow the user to drill down to the food they're looking for. Using a single Views 2 "Page" display, this is easy to do - just add an argument for the food type and have it display a summary when no argument is present: This will result in the showing only the food types when the page is displayed with no arguments: When one of the food types is clicked on, you'll see a list of matching foods: This works great and is easy to set up if this is what you're looking for. However, I find that often I'd like the summary and a listing of matching content to be displayed at all times. When there is no argument present, then I want a paged list of all the content as well as the summary. When an argument is present, I want the filtered content but I still also want the summary. This can be quite easily done using a display attachment.

Creating a Fading Image Slideshow in Drupal 5

Published February 6, 2009

I recently had a site that I do volunteer work for ask me if I could create an image slideshow for them on the home page of their Drupal 5.x-powered site. They wanted to showcase various large images on their homepage fading from one to another, as well as be able to control what images were contained in the slideshow. The solution had to be easy to use and maintain as they don't have a dedicated IT person on staff.

Moving the comment form without hacking core

Published September 30, 2008

One of the most frustrating things about Drupal's current architecture is that comments, and the form to post them, are attached to nodes and don't easily allow you to move them around in your TPL files. There really should be an easier way to just place them anywhere you'd like. Most times this doesn't get in your way, until you want to do some fancy layouts where your content is split into multiple columns on the page.

Rebuild your node_comment_statistics table

Published September 29, 2008

If you're like me, most of your projects are redesigns of existing sites. And if the site is already on some kind of CMS, this means importing content from the old system into Drupal, and to make it easy you'll do it with MySQL directly. There are pros and cons about this approach, which I am learning, and one of the cons is that content created by the database may not always get plugged into all of Drupal's various tables. Sure, you got the text into node, node_revisions, can your CCK tables, but there is more than meets the eye.

Import Hundreds of Taxonomy Terms using AWK

Published September 16, 2008

Today's challenge: your editors just handed you almost 200 taxonomy terms to add to the site, and you don't have the time or inclination to hit the taxonomy/n/add/term page for the next 2 hours or so... AWK to the rescue! Doing a simple CSV export of the term_data and term_hierarchy tables, you've got a pretty simple structure: term_data tid,vid,name,description,weight term_hierarchy tid,parent What you'll ultimately generate here is a file that stores everything you need to know about importing these terms via a CSV - the term names, the weights, good IDs, and the TID of the parents. 2048,#the current value of the sequences for term_data term,34,Blogs,#a helper line x,1,Drupal,All about Drupal,-5 x,1,Modules,Ways to extend Drupal,-4 x,1,Themes,Making your install pretty,-3 term,35,News,#a second helper line x,1,International,,0 x,1,Local,,0 x,1,Hyperlocal,,0 In this file, we've got 3 types of data: The starting value for sequences The id of the parent term for the next several rows, starting with the word "term" followed by the TID and the plain English name just to help us get organized The new terms, with an "x" where the new TIDs will be placed, and the VID, Description and Weight all filled out.

Custom GMap Solution for Dynamically Updated Markers (Part 2)

Published August 27, 2008

In my previous post , I talked about how I implemented the dynamic marker system on OffRoadAtlas.com . In this post, I'll cover the functionality that the PdMarker adds to the site. When you first hit the home page of the site, you'll see that the main content area is separated into two main sections: the narrow column to the left of the map (I call this the "info column") and the map itself. The idea behind the info column is that as users click on markers on the map, instead of the standard GMap info window, a very brief

Custom GMap Solution for Dynamically Updated Markers (Part 1) (Drupal 6)

Published August 25, 2008

I recently upgraded OffRoadAtlas.com with a custom map interface based on the GMap module. I was able to do this while leaving the GMap module is virtually un-hacked (with the exception of modifying the "GMAP_API_VERSION" variable) - all of the customizations were made via an additional "helper" module that was written specifically for this site. The site utilizes a map on the home page that shows all the off-roading areas and clubs in the database. The problem I was trying to solve was that I didn't want to have to load all 1,500+ points each time the home page was

US States list for CCK select boxes

Published August 22, 2008

When defining Content Types in Drupal with the Content Construction Kit you are able to add select boxes to them with CCK. It takes its key/value pairs in this format: Key|Value . One of the most common tasks for this is to create a drop down list of US States. So to save folks some time, I have compiled a list for you to paste right into your own projects. The attached text file will give you US States in the expected format. Hopefully this will save others a bit of typing when you need such a list for your own Drupal projects. Enjoy!

Drupal Theming: $path vs. base_path and path_to_theme

Published August 20, 2008

When developing Drupal themes, there is one bit of code you type over and over again: sites/all/themes/blueprint/images/whatever.jpg Where images/whatever.jpg could be a css file, or other file, but is normally an image. However, since clean URLs in Drupal appear to make fake directories, the web browser thinks your image is located in: node/345/sites/all/themes/blueprint/images/whatever.jpg When it's not. Luckily Drupal has tools to help you in this case.

Using Views 2 and Drupal 6 to Create a Related Pages Block

Published June 17, 2008

Today's question comes from Dale at NFi Studios in Orlando, FL - my home town: Essentially:, what i'm trying to do is 1. Determine the current nodes taxonomy terms 2. Determine all other pages that share taxonomy terms 3. Display the title (and link) to those pages in a block Using Drupal 6.2 and Views - Looked at a few modules, but nothing quite exact - Reviewing some module snippets right now to see if I can potentially use an argument to do it.

Using AWK to Download and Unpack Drupal Modules

Published June 16, 2008

When installing a new Drupal site (or when your list of available updates gets nice and long), you'll often have to download tons of modules, unpack them, and copy all of the resulting directories to your sites/all/modules directory. Personally, I'm not a fan of all the clicking, downloading, unzipping and most of all waiting! Today I finally settled on a workflow that gets the job done, and it's called the UNIX command line. If your server doesn't use some flavor of UNIX or Linux, or if your web host doesn't allow you shell access, you may want to stop reading after the next paragraph.

Creating Modal "Please Wait..." Dialog Boxes with jqModal jQuery Plugin (Drupal 6)

Published February 24, 2008

Part of the power of having jQuery integrated with Drupal is the ability to take advantage of the strong jQuery developer community. There are many, many plug-ins for jQuery that can add some great functionality to your site - usually with very little code. jqModal is just one of these plug-ins. It can be used to create modal (or non-modal) dialog boxes. In this example, I'm going to show you how to use it to create a modal "Please Wait..." dialog box. This can be useful when your user submits a form that might take a few seconds to process