Tutorials

Case Study: Building and Theming a 3,000 Article Site in 37 Days.

It could have been an April Fools joke.  On April 1st we got the call. "We have mockups for the design of the site, and we need the theme done in 2 weeks. After that we can discuss the XML import part of the project. We need to go live at the beginning of May."  We knew it would be a challenge, but we made it happen - on May 7th the site went live.

resources.yournaturaloptions.com home page

On Drupal Performance: Testing with Apache Benchmark

Sometimes in our lives, we all have pain, we all have sorrow. And sometimes we also have to launch Drupal sites into the wild blue yonder. It's during these times that we separate the grown-ups from the n00bs, and we see how well our site performs under heavy load. Many of us didn't need to worry about speed, page size, and server load in our younger years when we were building sites for Uncle Don and Aunt Sue, but eventually you get that big client, and you need some help.

Testing your site's performance

There are several ways to test, and a few metrics to acquaint yourself with. Not all metrics are created equal, but all of them are important at one time or other. In Part I of this post, you will be reading about testing with the Apache Benchmark tool on the command line.

Apache Benchmark

Magically Disappearing Default Search Text

Keeping a site's design as clean as possible is something all (well, okay, maybe not "all") designers and developers strive for. One relatively easy thing that you can do towards this goal is removing the supporting (and often unnecessary) text around your site's search field. I'm talking about the "Enter search terms" or "Search this site" text that floats innocently above or next to the text input box. Is this really necessary? I don't think so.

default Drupal search block

A much cleaner way of presenting a search box is with some default text inside the input field that automatically disappears when the user moves the cursor into the field.

Event Registration with Ubercart

Ubercart is arguably the leading ecommerce module suite for Drupal. It allows site admins to sell virtually just about anything online, including physical products, downloadable products, and event admissions. Often, when selling event admissions, it is desirable for the registrant to be able to fill out a profile during the checkout process that can be posted on the site once the transaction is complete. The UC Node Checkout module was built for this purpose. This is the way last year's Do It With Drupal conference handled registrations - with these exact modules.

UC Node Checkout page at drupal.org

Setting it up can be a little tricky, as it is not entirely a straight-forward process. Ryan Szrama, the de-facto leader of the Ubercart project, demoed this module during the recent DrupalCon DC. I thought I'd take the time to reproduce what Ryan did, as it is a great introduction to this module. Keep in mind it won't be an exact reproduction, but it should be pretty close.

This article will assume you're familiar with some very basic Ubercart concepts, if you're not, don't worry, this isn't rocket science. One thing you'll need to do if you're playing along at home is to create the "keys" directory for test credit card payments - full info on this is located at admin/store/settings/payment/edit/methods in your Drupal install (assuming you already have Ubercart enabled).

Using Display Attachments to Provide a Consistent Summary in Views 2

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.

Help! Anonymous User Comments Disappeared!

Looks like some MySQL data export/import operations can fail for anonymous users. I just did a data dump from my local development server to the live site and all the comments by users who aren't logged in were not showing up. Gone. Missing. It turns out MySQL was trying to stick the autoincrement value in the `uid` field in the place of the supplied `0`.

mysql auto increment

Import Hundreds of Taxonomy Terms using AWK

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:

  1. The starting value for sequences
  2. 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
  3. The new terms, with an "x" where the new TIDs will be placed, and the VID, Description and Weight all filled out.

Drupal Theming: $path vs. base_path and path_to_theme

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

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

Security Update RequiredWhen 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.

Editing HTML around Displayed View Fields: Views Theme Wizard

Question #2 also comes to us via our Facebook forum

Modifying existing views.

Michael Blake (Orlando, FL) wrote on Jan 24, 2008 at 12:08 PM.

I'm working on an existing Drupal application that has a custom Content Type. This includes some custom fields. When I change a custom field, such as add markup before and after it, This does not appear in my views. I think it's because my Views have been exported.

However if I change the .php files in the themes directory directly on the server, I get what I want. My question is , if I go about it this way, can someone else come along export a view and erase my changes? Or do I need to re-export every time I make a change?

Thanks.

XML Sitemap not associated with pathauto url aliases

This question comes to us from our Facebook forum. It feels good to answer, because this is the first of many questions we'll be answering here on the site.

Some Help I need (XML Sitemap)

wrote on Jan 8, 2008 at 5:52 PM.

So right now, I've been trying to fix an issue I have on my website. I imported everything I had from WordPress (posts, comments, categories/tags, etc), and then I installed the pathauto and the XML Sitemap modules. The problem I'm having is that XML Sitemap is producing a sitemap with every link in terms of nodes rather than the aliases my pages now have, and I would strongly prefer it to use the aliases. My NEW content is being included in the sitemap using aliases, but all the previously imported content is in the node format.

You can look at my sitemap if you're not sure what I mean, is http://omareduardo.com/sitemap.xml

Thanks for any help!
-Omar