Drupal Articles

Theme Drupal Breadcrumbs

Do you ever wish that you could style a specific breadcrumb in Drupal's breadcrumb trail? Well, you can. Drupal's handy theme_ functions allow you to selectively override any function that constructs a themed element.

To theme your breadcrumbs, use the theme_breadcrumb function. Simply add a new function to your template.php following this naming convention: [your_themes_machine_name]_breadcrumb. Take a look at my customized breadcrumb function for the "grasmash" theme. It does the following:

Remove (All Day) label from CCK Date field

By default, the Date module will will append the "(All Day)" tag to any CCK Date field for which the time (hours/minutes) input has been left empty. This is pretty annoying. There are many ways to work around this, but the simplest by far is to simple override the date_all_day_label() function in your theme's template.php file.

<?php
function grasmash_date_all_day_label() {
  return
'';
}
?>

You will need to replace "grasmash" with the name of your theme.

Search by Page - by Taxonomy Term

I recently submitted a submodule to the popular Search by Page module. It allows pages to be indexed according to their taxonomy terms (with depth modifier option). Still need to develop some tests to make sure that the module works in all scenarios, but it's a good start. Feel free to comment or pitch in!

Adding helpful classes and links top Drupal blocks via preprocessing: first, last, odd, even, edit, configure

Drupal's ability to preprocess HTML code in your theme's template.php file is extremely helpful for theme coding and site administration.You can find excellent preprocessing scripts on Drupal.org's forums, or simply use one of the many free Starter Theme such as Zen or Basic. I personally use the Basic Theme, which does quite a lot of theming work for you.

As great as Basic theme's template.php file is, there's still room for improvement. I've added four major improvements to it here:

How not to use' "Taxonomy: Term ID (with depth)" Argument

I could write a tutorial on how to use Views' two most nefarious arguments, "Taxonomy: Term ID (with depth)" and "Taxonomy: Term ID depth modifier," but I won't. There are plenty of those. Instead, I'll just tell you how not to use them.

If you're like me, you'll get very excited when you see a URL that looks like http://www.mywebsite.com/taxonomy/term1-name/term2-name. It will fool you into thinking that you can create a view which accepts infinite taxonomy term arguments, each separated with a pretty slash. Well you can't. At least, not exactly.

That tricky little URL is actually just an automated path alias that has been generated by pathauto. It's actually being translated to http://www.mywebsite.com/taxonomy/tid before it makes its way into views.

In truth, you can only create views that accept taxonomy terms in the following formats:

Drush - too many levels of recursion

I'm a total linux noob. So when I tried to manually set up Drush on a Linux server today, I ran into a bit of trouble. Following the Drush instructions, I put drush outside of the webroot and attempted to create a symbolic link between the Drush directory and /usr/bin.

The drush readme instructs a noob to do the following:

ln -s /path/to/drush/drush /usr/bin/drush

So, I navigated to the drush directory and tried to follow instructions:

cd /var/www/drush
ln -s drush /usr/bin/drush

Attempting to run Drush then gave this error:
bash: /usr/bin/drush: Too many levels of symbolic links

After a lot of fruitless Google searching, I decided to try again with a closer attention to detail:

Preserve destination with Rules' "page redirect" action

I often us the Rules module to redirect a user to the login page when they try to access protect content. Unfortunately, Rules' "page redirect" action doesn't preserve the destination parament, i.e., the node that the user was trying to view. Adding a small bit of php code to the redirect url fixes this issue:

To: user/login ?

<?php
destination
=node/[node:nid]
?>

Views Accordion - Opening a specific row with a link

Goal: create link that goes to a new page and opens a specific accordion drawer.

Using the Views Accordion module in combination with a little custom code accomplished this. Here's a step by step guide.

Create your view

-add this header with input filter "php code":

Using lightbox2 with the core menu system

If you'd like to make a menu item open in a lightbox, you can use the Lightbox2 module in tandem with the Menu Attributes module module to achieve a variety of effects.

Download and enable the Menu Attributes module.

This will let you add a rel attribute to any menu item. Add "lightframe" or one of the following rel values (as appropriate):

Pages