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
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:
- 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.
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



3 comments
Comment by kiwipearls on May 27, 2011 at 1:53 am
Yey, great artice.
I’ve been searching for something like this for the last few days and fiddled with views a lot to no avail.
This has definately helped me.
I have this to display an image from the users profile to make their blogs a bit more identifiable from another users blog.
But my problem is I cannot figure out how to put this block on the page that lists all the blog entries.
I have…
/blog – lists all blog entries with summaries
/blogs/username – a link to users blog
/blog/blogtitle – the article of a blog
It only displays on blog/blogtitle
and I want it on /blogs/username
I think it may have to do with pathauto or something. but I am completely new to Drupal.
Comment by Kevin Jones on August 10, 2011 at 3:57 pm
@kiwi
Hey Kiwi — I think you can get access to those fields (you are making a NODE view right, and need to add fields from USER on it?) by simply adding a “Relationship”
If you add a Relationship of “Content: Author” then check your fields you should have access to all your CCK fields inside the User type.
That should work.. if not, sorry, just my first idea, still newer to Drupal as well.
Comment by oilnam on October 6, 2011 at 3:17 pm
Hey, I stumbled upon this while I was looking for something different, but still: I had the same problem and I solved it in a slightly different way (thanks to the Drupal guys). And although I’m not 100% sure is the “definitive” way to do it, it’s a bit less tricky then hacking around with php-arguments. You can find the solution here: http://drupal.org/node/1279068
bye