Over the last few days, I’ve been working on a new website project and I decided to use Drupal 7 for it’s Content Management System (CMS). Most of my websites use either Drupal (version 6) or WordPress but because it’s been released for a while now, I decided to take the plunge and give Drupal 7 a shot.

The website project is Get-Rid.Org, an informational website devoted to providing advice on how to get rid of a variety of different things from bed bugs to styes – it’s still in the early stages of development and we need to get lots more content on there.

Anyhow, one of the things I wanted to integrate into the website was a an author info / author bio block on each page of content showing the name, a photograph and short bio of the person who wrote the article.

I thought it would be a piece of cake to set this up – just a simple module download,install and config – because it’s such a widely-used feature on many websites, however it ended up taking me a whole day to do!

So, what follows is how I did it. If you know of a better way (and I’m sure there must be a better way) I’d love to hear it in the comments section below :)


STEP 1: REQUIRED MODULES

My method uses the Views module, which also requires the Chaos Tool Suite Module, so the first thing to do is download and install them:

STEP 2: EXTRA USER FIELDS

Next, I set up some extra user fields to store the author’s full name and a short bio.

This was achieved by going to Administration » Configuration » People » Account settings, then filling in the form as follows:

  • Label -> Full Name
  • Field name -> fullname
  • Type -> Text
  • Widget -> Text field
Drupal 7: New user field

Drupal 7: New user field

And, for the Bio Field:

  • Label -> Bio
  • Field name -> bio
  • Type -> Long text
  • Widget -> Text area

Drupal 7 already provides a field to upload a profile picture, so do this and fill in the full name and bio details in each user’s profile.

STEP 3: THE VIEW

The next thing I did was to set up a new view by navigating to Administration » Structure » Views and clicking Add new view. I called the new view authorbio and of the User type.

I then changed the views basic configuration options:

  • Basic Settings > Title – About the Author
  • Basic Settings > Use Pager – Display a specified number of items (1)

and added the following fields:

  • User: Picture
  • Fields: field_bio
  • Fields: field_fullname

Note: The latter two fields are the ones I created in step 2.

Finally, I added an argument and configured it as such:

  1. Added the User: Uid field
if (arg(0) == 'node' && is_numeric(arg(1))) {
    $node = node_load(arg(1));
    $uid = $node->uid;
}
else{
    $uid=1;
}
return $uid;

This code checks to see if the current page is a node, and if so, grabs the user id of the nodes author and returns it. Many thanks to Chris Free of Chromatic for this :)

Then it was just a matter of creating a block display for the view (see pic below), saving it and moving the block to where I wanted it in Home » Administration » Structure » Blocks.

Drupal 7 Author Bio View

Drupal 7 Author Bio View

 

And, Hey Presto!, it works :)

Unfortunately, despite it working, it doesn’t feel like a good solution and I’m sure it won’t be long before someone makes a cool module that does the job a million times better.

In the meantime, however, this is working, so I’m happy :D