Drupal coder

Keeping track of backlinks in Drupal 7

A popular feature request for sites that deal with a lot of content, is to see for each page what other pages are linking back to it. This can be helpful when doing some SEO or cleaning up and rewriting old content.

In Drupal 7 this is easily done. It exists where you wouldn't immediately expect it though: the core search module. Kind of mimicking how search bots like Google's indexer works, Drupal 7's search module now takes the amount of nodes linking back to another node to calculate the score for some result.

August 22, 2010Drupal 7, Drupal, maintenance, search, SEO

Share your Mollom stats

A request was just sent out on Mollom's Twitter account to help them spread the word on Mollom. Since I've been an extremely satisfied user of this (free) anti-spam service for about 2 years now, I immediately added a link back to them in the footer of this blog. But I decided that's not enough. So I'd like to start a little meme here.

If you're happy about Mollom, just shout it out on Twitter, Facebook, your blog, ... by putting up a screenshot of your stats and saying how many spam has been caught by Mollom. You can find the stats of your site on your Mollom account. If you're using Drupal, you can find them under Administer > Reports > Mollom Statistics.

If you're using Twitter, use the hashtag #mollomstats. I'm looking forward see how much crap content Mollom has spared us from.

I'll give the example by being the first...

May 21, 2010anti spam, Drupal, Mollom

An overview of Drupal's cache_clear_all uses

Drupal has a very simple, yet powerful (low level) caching system. It provides 3 functions that should please all you caching needs: cache_get, cache_set and cache_clear_all. The first two are pretty straight forward to use, but the third one might take some time to wrap your head around.

It accepts 3 argument: a cache ID, table cache and a wilcard boolean. Each combination of these 3 has a very different result. Here's an overview of all combinations.

May 19, 2010Drupal, performance

How to define page callbacks that you don't want to render using page template in Drupal?

Defining custom pages in your Drupal module is easy using hook_menu and a callback function. Let's have a look at an example.

/**
 * Implementation of hook_menu().
 */
function my_module_menu() {
  $items['hello'] = array(
    'title' => 'Hello world',
    'page callback' => 'my_module_page',
    'access callback' => TRUE,
  );
}

function my_module_page() {
  return t('Hello world');
}

In this example, going to /hello will show you a page saying "hello world" rendered using your page template. So this page will display with your logo, blocks, footer, ...

In some cases you don't want this. Mostly in case you won't return HTML but something like XML, JSON, ... Let's have a look at two ways how this can be accomplished.

Theme variables available to all Drupal template files

When writing themes there's a few values we frequently need to access in our templates. I'm thinking about stuff like "is the user logged in", "is the user an admin", "what is the theme directory" (for referencing images etc)?

The good news is that all these and a few more are available in all template files. Here's a listing of what variables are available and how you can add your own.

May 14, 2010Drupal, theming

drupalcoder.com is a blog on all things Drupal in specific and LAMP on OS X in general. It is maintained by Davy Van Den Bremt, a Belgian (Drupal) web developer and designer living in Ghent. The goal of this blog is to log all interesting things that have crossed the writer's path while developing Drupal sites. You can read all about Davy's professional activities on his LinkedIn profile. If you want to get in touch, use the contact form.