Warning: Table './db79366_designmess/sessions' is marked as crashed and should be repaired query: SELECT u.*, s.* FROM users u INNER JOIN sessions s ON u.uid = s.uid WHERE s.sid = '15c9adbf56f05cc73f1f1f6b550d18ab' in /nfs/c05/h04/mnt/79366/domains/designmess.com/html/includes/database.mysqli.inc on line 128

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /nfs/c05/h04/mnt/79366/domains/designmess.com/html/includes/database.mysqli.inc:128) in /nfs/c05/h04/mnt/79366/domains/designmess.com/html/includes/bootstrap.inc on line 1037

Warning: Cannot modify header information - headers already sent by (output started at /nfs/c05/h04/mnt/79366/domains/designmess.com/html/includes/database.mysqli.inc:128) in /nfs/c05/h04/mnt/79366/domains/designmess.com/html/includes/bootstrap.inc on line 636

Warning: Cannot modify header information - headers already sent by (output started at /nfs/c05/h04/mnt/79366/domains/designmess.com/html/includes/database.mysqli.inc:128) in /nfs/c05/h04/mnt/79366/domains/designmess.com/html/includes/bootstrap.inc on line 637

Warning: Cannot modify header information - headers already sent by (output started at /nfs/c05/h04/mnt/79366/domains/designmess.com/html/includes/database.mysqli.inc:128) in /nfs/c05/h04/mnt/79366/domains/designmess.com/html/includes/bootstrap.inc on line 638

Warning: Cannot modify header information - headers already sent by (output started at /nfs/c05/h04/mnt/79366/domains/designmess.com/html/includes/database.mysqli.inc:128) in /nfs/c05/h04/mnt/79366/domains/designmess.com/html/includes/bootstrap.inc on line 639
Using Drupal: Snippets, Themes, and Resources | [field_tutorial_category-term] | Designmess

Using Drupal: Snippets, Themes, and Resources

Submitted by on

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

  1. <?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.

  1. <?php
  2. #in template.php:
  3. function custom_count_pull(){
  4. $sql = "SELECT type, COUNT(nid) AS number, FROM_UNIXTIME(created, '%Y') AS createdate FROM {node} GROUP BY type, createdate ORDER BY createdate DESC";
  5. $result = db_query($sql);
  6. $article_count = array();
  7.  
  8. while ($data = db_fetch_object($result)){
  9. if (isset($article_count[$data->type])) {
  10.  
  11. $article_count[$data->type][$data->createdate] = $data->number;
  12. } else {
  13. $article_count[$data->type] = array($data->createdate => $data->number);
  14. }
  15. }
  16. $today = date("Y");
  17. $years = array($today-2,$today-1,$today);
  18.  
  19. $output .= "<table><tr><th>Type</th><th>{$years[0]}</th><th>{$years[1]}</th><th>{$years[2]}</th></tr>";
  20. foreach ($article_count as $type => $value) {
  21. $real_type_name = node_get_types('name', $type);
  22. $output .= "<tr> <td>$real_type_name</td>";
  23.  
  24. foreach ($years as $year) {
  25. if ($value[$year]):
  26. $output .= "<td>{$value[$year]}</td>";
  27. else:
  28. $output .= "<td>0</td>";
  29. endif;
  30. }
  31. $output .= "</tr>";
  32. }
  33. $output .= "</table>";
  34. return $output;
  35. }
  36. ?>

And then, use this PHP code wherever Drupal allows PHP input:

  1. <?php
  2. print custom_count_pull();
  3. ?>

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.

  1. <?php
  2. // in your template.php file
  3. function output_field($title,$field){
  4. $output = '<div class="field field-details">
  5. <h3 class="field-label">'.$title.'</h3>
  6. <div class="field-items">';
  7. foreach ((array)$field as $item) {
  8. $output .= '<div class="field-item">'.$item['view'].'</div>';
  9. }
  10. $output .= '</div></div>';
  11. return $output;
  12. }
  13. ?>

Then, to output the field, use this code:

  1. <?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

  1. <?php
  2. $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");
  3.  
  4. $output = "<ul>";
  5. while ($user = db_fetch_object($users)) {
  6. $output .= "<li>" . l($user->name, drupal_get_path_alias("user/{$user->uid}")). " ($user->count)</li>";
  7. }
  8. $ouput .= "</ul>";
  9. echo $output;
  10. ?>

You can just change limit 10 to whatever number of commentors you want to show.

Show top Authors

  1. <?php
  2. $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");
  3.  
  4. $output = "<ul>";
  5. while ($user = db_fetch_object($users)) {
  6. $output .= "<li>" . l($user->name, drupal_get_path_alias("user/{$user->uid}")). " ($user->count)</li>";
  7. }
  8. $ouput .= "</ul>";
  9. echo $output;
  10. ?>

Once again, change limit 10 to whatever you want.

More Snippets

If you are looking for more Drupal snippets, check out these resources:

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:

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:

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.

About Sean GengMember Since 08/03/2009

Web Designer, Web Developer

My name is Sean Geng. I'm a Freelance Web Designer, Graphic Designer, Motion Effects Artist, and Webmaster. I like to push the boundaries. I love creating unique, clean, usable design for the web and other digital sources.

CommentsAdd your comment

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <h3> <h4> <i> <b> <p> <a> <br /> <img> <em> <strong> <blockquote> <cite> <code> <ul> <ol> <li> <div class="info-block-left"> <div class="info-block-right"> <div class="quote-left"> <div class="quote-right"> <div class="notice"> <table> <thead> <tbody> <tr class="odd"> <tr class="even"> <tr> <td> <th>
  • You may post PHP code. You should include <?php ?> tags.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <actionscript-code>, <actionscript3-code>, <apache-code>, <asp-code>, <css-code>, <html-code>, <javascript-code>, <mysql-code>, <php-code>, <python-code>, <ruby-code>, <sql-code>, <xml-code>. The supported tag styles are: <foo>, [foo].
  • Images can be added to this post.
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.
  • Links to HTML content with 'rel="lightframe"' in the <a> tag will appear in a Lightbox when clicked on.
  • Each email address will be obfuscated in a human readable fashion or (if JavaScript is enabled) replaced with a spamproof clickable link.
  • You may insert videos with [video:URL]

More information about formatting options

Other stories you might like

Sorry if its gonna be slow content wise for a week or so. Working on a free wordpress theme. Consider writing for us?