How to create an 'about the author' block in Drupal 7 using views.

If you've ever created a site with multiple authors and wanted to automatically display some information about the author on the posts written by that author, it's pretty easy to implement using views in Drupal 7. Below is a quick tutorial on how to accomplish this. 

Required modules

  • Views

Create the view

  1. Create a new view called 'About the Author'
  2. Assuming that you will be displaying information from the author's user account, you should specify the view to show Users.
  3. In this example, we will be putting the 'About the Author' information in a block so that it can be placed in whatever region you choose. So you can uncheck the Create a page box, but be sure to check the Create a block box.
  4. Since there is only going to be a single author for each post, you can set the items per page to 1.
  5. Click  Continue & edit.

Configure the view

  1. For this example, I am going to be showing fields in an unformatted list. The fields you choose to include, or the format you choose to display them in doesn't really matter. What's important is how you get the correct author information to show up on the correct page. To do this, we'll be using a contextual filter.
  2. After you select the fields you want to include in your about the author block, click on the Advanced link on the right to expose the advanced settings.
  3. Next to Contextual Filters click add, then search or scroll to find the User: Uid filter and select it. 
    If you're unfamiliar with contextual filters, sometimes it can be hard to figure out exactly what contextual filter you should be using. For me it helps to thing about what information I am trying to retrieve from the database and then think about how I would limit the result set if I were using a static filter. So in this example, the information I am trying to retrieve is a the author's name and picture. I know that this information is coming from their user acount, so if I were using a static filter and I wanted to see the name and image of a single author, I would filter by the author's user id. Just like if I were looking for the title of a single node, I would filter by a node ID.  
  4. Now that we know we want to filter by the User ID, the next step is figuring out how to supply that to the view. Unfortunately this is trickier than it needs to be, but only because of the language used in the views interface. Typically view's contextual filters come from the URL, but in this case since we're looking for a user ID, it's probably not going to be found in the URL of an article or blog post. So in the first group of configuration options for this contextual filter, select the Provide default value option.
  5. This is where the tricky language comes in. Although we're working under the assumption that the user ID is not part of the URL, the option we want to select is User ID from URL. Why? Because when you select that option, a checkbox appears that says "Also look for a node and use the node author." Basically what this is saying is, on this page, if it's a standard drupal path like node/11, look into that node object and find the user ID of the node's author. This is will get us the user ID that we want to use for the value of the contextual filter, so go ahead and click on that checkbox.
  6. Lastly we want to specify our validation criteria. So check the box that says Specify validation criteria and for the validator select User. Then, since we know we're filtering on a user ID, we can choose the option that says Only allow numeric UIDs.  And for the action to take if the filter value does not validate, we can select Hide view.
  7. Click apply, and if you want to test the contextual filter, scroll down and type the user ID of one of the authors on your site. You should see that the information that is returned is from the user with that user ID.

Place the block

  1. Save the view and go to the blocks administration page. 
  2. find the block that you just created and place it in whatever region makes sense. You can also specify which node types you'd like this block to appear on, as well as the user roles you'd like to be able to see the author information.