Skip to main content

Blog

How to add a class to a Drupal 7 region

Today I needed to add a class to a Drupal 7 region and found the lovely template_preprocess_region() function to do the dirty work for me. With this function, you can easily add any class to your regions with the code below.

In a nutshell, you find the region you want to add the class to and then append your class onto the end of the classes_array variable.


Having a node's field show in a block region.

I'm currently building a website that has a three columned layout. The left most column contains the navigation elements, the center column contains the body, and the right side column contains supporting text for the article. So I created three block regions in my theme: left_sidebar, content, and right_sidebar. The problem I ran into was that the text in the right side column was different for every node. Having the user create a separate block for each node seemed very inefficient.


jQuery Photo Galleries: Some awesome ones I've found

This is a list of some of the more unique, excellent photo galleries I've come across.

Full screen, would be good for a touch screen interface:
- http://tympanus.net/codrops/2010/05/14/sliding-panel-photo-wall-gallery…

Another cool gallery with a polaroid look and sliding galleries:
- http://tympanus.net/codrops/2010/06/27/beautiful-photo-stack-gallery-wi…


Deleting File Attachments with Drupal's node_save() Function

Today I ran into an issue of needing to programmatically remove file attachments from a node. To accomplish this I referred to the upload_nodeapi() function and found the upload_save() function. After examining the code I found that upload_save looks for the 'remove' parameter for the file object. If $file->remove exists, the file will be deleted from the database and file system. So by adding the 'remove' parameter to the files I needed removed before calling node_save() results in the files being removed from the node upon calling node_save(). Done!


Drupal 7: Feeds Import: Generating the correct .csv

Today I needed to import about 2000 user accounts into a new Drupal 7 database. To do this I decided to use the Feeds module which includes a Feeds Import module. Perfect! First, I went to the feeds admin interface and setup the import by mapping all of my fields to the .csv. Next, I opened Excel and generated my spreadsheet. Once that was completed I saved the spreadsheet as a .csv file and tried to import. The form returned with the following message "0 users created". WTF!


Ubercart: Add Unit Price to the Shopping Cart Table.

We are working on an Ubercart store running Drupal 7 and we needed to add the price per unit to the shopping cart page. I didn't see any options for enabling this in the store administration area so I began looking for some code to make this happen. I came across this post, http://pixeljets.com/blog/adding-price-field-ubercart-cart-page, which was close to what I needed, but I figured there was a theme function I could use instead of a custom module.


Drupal Views Slideshow: Prevent widowed items on slides.

We have a site that is running the views slideshow module to display advertisement images. Recently a client asked us to prevent these advertisements from displaying only one item on the screen. In order to do this I began dissecting the views slideshow module code and I came across the template_preprocess_views_slideshow_cycle_main_frame() function. This function takes care of rendering the rows.


Drupal Multisite: Preventing a sub-site from getting indexed by search engines

Today I needed to prevent a Drupal 6 website from getting indexed by the search engines. This would normally be a relatively easy task by having the robots.txt file disallow everything. The problem I ran into was that I was using Drupal's multisite feature and I needed to prevent a sub-domain from getting indexed while the main site continued getting indexed.


Views: Taxonomy Term View: Display only one node per taxonomy term.

Today I was setting up a website that was using FlickrSync to pull images from Flickr. FlickrSync creates one node per image and uses Flickr's tags as taxonomy terms. Perfect.

I created a new Term view to pull all taxonomy terms associated to the 'Gallery' vocabulary I had created. The problem I ran into was that the view pulled ALL image nodes tagged with each gallery term. This was not what I was looking for. Instead, I wanted a list of each term and one image node, not all nodes.


Registering views_handlers for Views 3 and Drupal 7

I've recently been exposing a custom module's data to views 3 in Drupal 7. I copied the code from the uc_product module and for some reason, I couldn't get my views handlers to get registered with the system. Everything I tried would result in a broken/missing handler error. After scouring the online views documentation, http://views.doc.logrus.com, I finally found a line directing me to the advanced help module.


Drupal Menu: Add Primary Menu Parent to the Beginning of the Secondary Menu

Today I needed to take the parent menu item from my primary links and add it to the beginning of my secondary menu links. To begin, my menu structure looks like this:

  • Primary 1
  • Primary 2
    • Secondary 2.1
    • Secondary 2.2
    • Secondary 2.3
  • Primary 3

Default Menu Setup

The $main_menu variable will print a list item with:

  • Primary 1
  • Primary 2
  • Primary 3

When you click on the 'Primary 2' link the $secondary_menu variable will display: