Using Drupal: Snippets, Themes, and Resources
What is Drupal?
I guess it seems appropriate to explain what Drupal is. Drupal is an open source content management platform. Similar to Wordpress, Joomla, and many more. Take it from the Drupal website itself:
Drupal is a free software package that allows an individual or a community of users to easily publish, manage and organize a wide variety of content on a website. Tens of thousands of people and organizations are using Drupal to power scores of different web sites, including:
- Community web portals
- Discussion sites
- Corporate web sites
- Intranet applications
- Personal web sites or blogs
- Aficionado sites
- E-commerce applications
- Resource directories
- Social Networking sites
You can download the latest version over at Drupal.org.
Getting Started
To get started, download the latest version and unpack it on your web server. Fill out the database information and wait for it to finish installing. For more detailed and step by step instructions, follow Drupal's install guide.
After following the on screen instructions and finishing your installation, you can begin by installing some themes and some modules.
Lucky for you, all of Drupal's modules and themes are available on their download page.
Must have Modules
Modules are basically addons that extend your site's functionality. In Wordpress, you would know these as plugins. While the core Drupal install is great for starting a small blog, using modules to enhance and transform it into something completely different is exactly what Drupal is for.
Views
The Views module provides a flexible method for Drupal site designers to control how lists and tables of content (nodes in Views 1, almost anything in Views 2) are presented. Traditionally, Drupal has hard-coded most of this, particularly in how taxonomy and tracker lists are formatted.
This tool is essentially a smart query builder that, given enough information, can build the proper query, execute it, and display the results. It has four modes, plus a special mode, and provides an impressive amount of functionality from these modes.
Among other things, Views can be used to generate reports, create summaries, and display collections of images and other content.
The Views module is pretty the go to module for dynamically generating custom pages and content.
CCK
The Content Construction Kit allows you to add custom fields to nodes using a web browser.
CCK is essential for changing your node forms. Adding custom fields (like categories, attaching files, etc) to your forms.
Pathauto
The Pathauto module automatically generates path aliases for various kinds of content (nodes, categories, users) without requiring the user to manually specify the path alias. This allows you to get aliases like /category/my-node-title.html instead of /node/123. The aliases are based upon a "pattern" system which the administrator can control.
Like the description says, pathauto cleans up your node paths. By default, Drupal assigns all your nodes (content) a number; but pathauto will automatically replace that with your own defined path.
Imagecache
ImageCache allows you to setup presets for image processing. If an ImageCache derivative doesn't exist the web server's rewrite rules will pass the request to Drupal which in turn hands it off to ImageCache to dynamically generate the file.
Imagecache is extremely useful for generating thumbnails dynamically and automatically.
Panels
The Panels module allows a site administrator to create customized layouts for multiple uses. At its core it is a drag and drop content manager that lets you visually design a layout and place content within that layout. Integration with other systems allows you to create nodes that use this, landing pages that use this, and even override system pages such as taxonomy and the node page so that you can customize the layout of your site with very fine grained permissions.
Panels lets you create custom layouts on your pages.
Page Title
The word "title" is a bit overloaded. Every piece of content in Drupal has a title, and so does every page. The page title is the one found in the HTML head inside the tag. It is also used on SERPs (Search Engine Result Pages) and can greatly enhance your websites SEO (Search Engine Optimization).
This module gives you granular control over the page title. You can specify patterns for how the title should be structured and, on content creation pages, specify the page title separately to the content's title.
Browse the modules
Customize your own Drupal installation for your own needs. Pick up the modules you need, and make your Drupal site unique. There are a ton of good modules out there, and any combination of them will make your site stand out.
Drupal Snippets
We've rounded up the snippets we thought were the most useful. Of course, there are a endless amount of possibilities as to how you use them. If you have a basic understanding of PHP, there's a good chance you'll be able to know how to use these snippets. But if you don't, that's ok too. Just copy and paste the code where Drupal will accept it.
Show Login Form Anywhere
<?php print drupal_get_form('user_login') ?>
Placing the code anywhere where Drupal allows a PHP input (blocks, pages, etc), will print a login form.
Get Node Count for everything
Paste this in your theme's template.php file.
<?php #in template.php: function custom_count_pull(){ $sql = "SELECT type, COUNT(nid) AS number, FROM_UNIXTIME(created, '%Y') AS createdate FROM {node} GROUP BY type, createdate ORDER BY createdate DESC"; $result = db_query($sql); while ($data = db_fetch_object($result)){ $article_count[$data->type][$data->createdate] = $data->number; } else { } } $output .= "<table><tr><th>Type</th><th>{$years[0]}</th><th>{$years[1]}</th><th>{$years[2]}</th></tr>"; foreach ($article_count as $type => $value) { $real_type_name = node_get_types('name', $type); $output .= "<tr> <td>$real_type_name</td>"; foreach ($years as $year) { if ($value[$year]): $output .= "<td>{$value[$year]}</td>"; else: $output .= "<td>0</td>"; endif; } $output .= "</tr>"; } $output .= "</table>"; return $output; } ?>
And then, use this PHP code wherever Drupal allows PHP input:
<?php print custom_count_pull(); ?>
This will output a table with all the nodes and their count.
Output CCK Fields
If you are using Content Construction Kit (CCK), and you want a simple function to output the fields, then place this code in your template.php file.
<?php // in your template.php file function output_field($title,$field){ $output = '<div class="field field-details"> <h3 class="field-label">'.$title.'</h3> <div class="field-items">'; $output .= '<div class="field-item">'.$item['view'].'</div>'; } $output .= '</div></div>'; return $output; } ?>
Then, to output the field, use this code:
<?php print output_field('First Name',$field_first_name) ?>
Replacing "First Name" and $field_first_name with the name of your CCK field.
Show top Commentors
<?php $users = db_query("SELECT COUNT(cid) AS count, name, uid FROM {comments} WHERE uid != 1 and uid != 0 GROUP BY uid ORDER BY count DESC LIMIT 10"); $output = "<ul>"; while ($user = db_fetch_object($users)) { $output .= "<li>" . l($user->name, drupal_get_path_alias("user/{$user->uid}")). " ($user->count)</li>"; } $ouput .= "</ul>"; echo $output; ?>
You can just change limit 10 to whatever number of commentors you want to show.
Show top Authors
<?php $users = db_query("SELECT COUNT(n.nid) count, u.name, u.uid FROM {users} u LEFT JOIN {node} n ON u.uid = n.uid WHERE u.uid != 0 AND u.uid != 1 AND n.uid = u.uid AND u.status = 1 AND n.status = 1 GROUP BY n.uid ORDER BY count DESC LIMIT 10"); $output = "<ul>"; while ($user = db_fetch_object($users)) { $output .= "<li>" . l($user->name, drupal_get_path_alias("user/{$user->uid}")). " ($user->count)</li>"; } $ouput .= "</ul>"; echo $output; ?>
Once again, change limit 10 to whatever you want.
More Snippets
If you are looking for more Drupal snippets, check out these resources:
-
Drupal Block Snippets
A archive of snippets to be used in blocks. -
Drupal Mini Module Snippets
Snippets that act like mini modules. -
Drupal Page Snippets
Snippets for theming and page snippets. -
DrupalSnippets.com
A collection of Drupal snippets.
Theming
Once you have your installation complete, you'll probably want to theme your site. You can either download a free theme from Drupal's themes page, or build your own.
If you are choosing to download one of Drupal's free themes, here are some we recommend:
Zen
Zen is the ultimate starting theme for Drupal. If you are building your own standards-compliant theme, you will find it much easier to start with Zen than to start with Garland or Bluemarine. This theme has fantastic online documentation and tons of code comments for both the PHP (template.php) and HTML (page.tpl.php, node.tpl.php).
After using this theme myself, I'd have to agree that Zen is a excellent starting theme to build your own custom theme off of. The documentation is superb, and it explains everything well.
Acquia Marina
- 1, 2, or 3 column layout
- Selectable fluid or fixed width layouts and font stacks
- 15 collapsible block regions
- Drop-down primary links menu
- Includes icons for core and Views blocks
- Cross-browser tested in IE6/7, Opera, Safari, and Firefox
Fusion
Fusion is a powerful base theme, with layout and style configuration options built in that you can control through Drupal's UI. It's based on a simplified 960px or fluid 16-column grid. It's designed to be used with the Skinr module, with numerous useful block styles included.
Fusion is yet another great base theme. You can easily build your custom theme off of this.
Ad Novus
- Fluid and fixed-width versions both included
- W3C Valid, and tested on Firefox, IE7, Netscape, Opera, Safari
- Support for two, one, and no columns
- Support for logo, primary links, mission, search box, shortcut icon and user pictures
Fervens
- Supports all default Drupal theme features; Logo, site name, slogan, mission, node user pictures, comment user pictures, search box, favicon, primary links, and secondary links.
- Choose between the best of both worlds; fixed or liquid width (theme settings).
- Choose between 3 column types and positioning (theme settings).
- 9 available block regions optimised for advertisement placements.
- Nifty rounded corners on selected block regions.
- Integrated Superfish dropdown menus (primary links).
- Right-to-left (RTL) support.
- Completely CSS based, tableless design.
- Validates XHTML 1.0 Strict and CSS 2.1.
- Compatible and tested with all major web browsers; Firefox 3, Firefox 2, IE8, IE7, IE6, Google Chrome, Safari, Opera.
- Supports IE6 and below with the help of Whatever:hover script and IE PNG Fix.
ColorPaper
- Supports logo or site name, mission, comment user pictures, shortcut icon, and primary and secondary links.
- Fixed width layout with 2 columns.
- Maintenance/site off-line theme.
- CSS based, tableless design.
- Validates as XHTML 1.0 Strict and CSS level 2.1.
- Compatible and tested with Firefox 3, Firefox 2, IE7, IE6, Google Chrome 1, Safari 3.2, Opera 9.6.
- Comes with 5 variation of colours (teal, green, orange, pink, purple).
- Custom RSS feed button.
- Logo template (PhotoShop source file).
- PNG fix for IE5.5+.
More Themes
Of course, there's plenty of choices out there. Here are some resources for finding a Drupal Theme:
-
Drupal Theme Archives
The offical Drupal themes page with a huge collection of themes. -
Drupal Theme Garden
The theme garden allows you to preview themes live. -
Drupal Theme Guide
The Official Drupal Theming Guide. -
Drupal Theming Cheat Sheet
Very helpful cheat sheet detailing all the theming tags and identifiers.
Improving Performance
Its quite possible that after you install all your modules and themes, your Drupal site may seem a bit sluggish. Here are some modules and techniques to improve your site's speed.
Boost
Boost provides static page caching for Drupal enabling a very significant performance and scalability boost for sites that receive mostly anonymous traffic. Boost is very easy to install and has been throughly tested on Shared, VPS and Dedicated hosting. Apache is fully supported, with Nginx, Lighttpd and IIS 7 semi-supported. Boost will cache & gzip compress html, xml, ajax, css, & javascript. Boosts cache expiration logic is very advanced; it's fairly simple to have different cache lifetimes for different parts of your site. The built in crawler makes sure expired content is quickly regenerated for fast page loading. For shared hosting this is your best option in terms of improving performance.
Boost is your go to module for improving your Drupal's speed. It provides many configuration options, and should be the first module you take a look at to pick up your site's speed.
Javascript Aggregator
The aim of the JavaScript Aggregator module is to improve performance of your site with less server requests and bandwidth per page. In Drupal 5, all the JavaScript files will be aggregated into one file and optionally minified. JavaScript aggregation was brought into core with Drupal 6, so the Drupal 6 version of this module goes one step further to minify that file.
JS Aggregator is great if you have a lot of javascript running on your site. It condenses all of that into a packed file.
CSS Gzip
This module gzips your CSS and saves your visitor valuable time spend download the CSS file.
Further Reading on Improving Performance
There are some great articles and tutorials out there dedicated to helping you get the most out of your Drupal site. Here are just a few:
- Improving Drupal's Page Loading Performance
A great tutorial on how you can improve Drupal's loading speed. - How I Survived a 2300% Traffic Increase With Drupal
A personal account by a fellow Drupal site maintainer about how he configured Drupal to stand up to a huge traffic increase.
Feedback Welcome
I hope you enjoyed this tutorial, and found the resources useful. If you have a question or want to share your thoughts, please leave a comment using the form below. We'd love to hear what you thought.
Internet Nerd, Design Freak, oh and Designmess Admin.
- 2982 reads
Sign up
Register for an account to be able to post, critique, upload designs, and much more. What are you waiting for? Join in on the fun!


























CommentsAdd your comment
Post new comment