PHP

Sep 16 2011

Screencast: Creating and Theming a Node Photo Gallery with Drupal 7 and Colorbox

Recently, I designed, themed and developed a new site for my photography, High Rock Photo. The obvious choice for this new site was to use Drupal 7. I wanted the ability to easily create node galleries and this screencast shows you how to create and theme a node photo gallery using Drupal 7. I will also point out what modules are needed and make reference to those that would have been used in Drupal 6 and are now integrated into core in Drupal 7.


Feb 18 2011

Using Drupal Views Arguments to Show Results Only When a Filter is Used

Recently I was configuring a Drupal view for a client's website that consisted of the user inputting a zip code and distance to find a store near them. I was using an exposed proximity search filter with a postal code in combination with the Gmap and Location Modules.
Using Drupal Views Arguments to Show Results Only When a Filter is Used


Dec 30 2010

How to add a block region to a node page in Drupal 6

As a Drupal themers / front end developers, we are always asked to push the envelope of what's possible with design and theming. With Drupal 6, custom block regions are usually added in page.tpl.php which is normally outside of the actual page node content / comments. It would be above, below content or in sidebars typically. Occasionally you have the need to add a block region within a node area. This comes in handy especially if you are using a custom themed node page that uses CCK fields, e.g., "node-[custom_content_type].tpl.php".  To accomplish this there are a few steps involved.


Oct 20 2010

Theming Unique Home Page Elements in Drupal 6 with $is_front & PHP

Theming Unique Home Page Elements in Drupal 6 with $is_front & PHP

Ask 10 Drupal Themers how they would accomplish a task in Drupal and you just might get 10 different answers. Most likely those 10 different ways of accomplishing the task would all be valid and unique. This concept would apply when theming a home page element in Drupal; there are several different ways of going about this. For example, you could use page-front.tpl.php, Panels, Context, the front page module or custom body classes -- well the list goes on.


Sep 20 2010

Add an Auto Reply Email Message to a Drupal Webform with PHP

We are developing a Drupal site for a client and were tasked with adding an auto reply email to the user who submits a web form on the site. I thought for sure that the Drupal Webform Module we are using would have this function built in, however it did not.

With a little research and digging, it was trivial to add some post processing PHP to the Webform Module. We are using Webform 6.x-3.2 but this should also work with any versions of Webform 6.x-2.x.


Jul 26 2010

Theming breadcrumb output with PHP & CSS in Drupal 6

Theming breadcrumb output with PHP & CSS in Drupal 6

We have been developing a Drupal 6 site where we needed more control over breadcrumb theming.

Using the PHP code below, you can get unique & identifying classes to each part of the breadcrumb. You can than use CSS to style it however you like. Add the code to your template.php file in /sites/all/themes/[your theme]. Also make sure to change "yourtheme" to the actual name of your theme. If you don't have this file you can create one. Either way make sure to clear your site cache for your custom breadcrumb classes to show up. That's all there is too it, the rest is up to you in terms of how you style with CSS.


Jun 2 2010

Creating Custom Content Type Page Templates with Drupal & PHP

Creating Content Type Page Templates with Drupal & PHPWe were recently asked to create custom landing pages for a Google ad campaign for a Drupal site we developed. The issue we faced was that the layout for the landing page was not really close to anything in the existing theme.

Drupal by default can do custom node type templates based off any given custom content type (node-blog.tpl.php for example) but all that does is theme and customize the content area. In our case we needed to change the entire page layout. Well it turns out there is a Drupal PHP preprocess function that can help accomplish custom page templates.


May 10 2010

Custom Body Class with PHP for advanced Theming and CSS in Drupal 6

I recently developed a Drupal site where each page in the site was based on a custom content type and needed some very specific theming. Although my custom theme was based on 960.gs, I decided to borrow from the zen theme its custom body class implementation to give more meaningful CSS classes to leverage for theming.


Apr 1 2010

How to Customize and Theme Post and Date info in Drupal

When I was theming my blog in Drupal, I decided I wanted a better way to customize and display post info such as wording used and the way date was displayed. The first step is to have a look around and see where the code is coming from that renders this info. I viewed the files in my custom theme folder and discovered these few lines of code in node.tpl.php

  1. <?php if ($submitted): ?>
  2.     <span class="submitted"><?php print $submitted ?></span>
  3.   <?php endif; ?>

In HTML, that is rendered as:
  1. Submitted by highrockmedia on 4-01-10


Mar 1 2010

Remove Link from Image Attach in Drupal

UPDATE: Note, the code below may be out of date or not work with the newest version of image attach.

If you are using the Image Attach module in Drupal, you may not always want to have the image linked. Drupal links the image automatically to its own image node but sometimes you don't want that.

You can add an overide to your theme's template.php file. Note where it says 'your_theme' on line one, replace that with the name if your actual theme. You should also clear your Drupal cache after adding this code.

  1. function your_theme_image_attach_body($node, $iid) {
  2.   $img_size = variable_get('image_attach_size_body_'. $node-&gt;type, IMAGE_THUMBNAIL);
  3.  
  4.   if ($img_size != IMAGE_ATTACH_HIDDEN) {
  5.     drupal_add_css(drupal_get_path('module', 'image_attach') .'/image_attach.css');
  6.  
  7.     $image = node_load($iid);
  8.     if (!node_access('view', $image)) {
  9.       // If the image is restricted, don't show it as an attachment.
  10.       return NULL;
  11.     }
  12.     $class = 'image-attach-body' . ($image-&gt;status ? '' : ' image-unpublished');
  13.     $info = image_get_info(file_create_path($image-&gt;images[$img_size]));
  14.  
  15.     $output = '
  16. </p><div class="' . $class . '">';
  17.     $output .= image_display($image, $img_size);
  18.     $output .= '</div><p>'."\n";
  19.  
  20.     return $output;
  21.   }
  22. }