Have a question? Want to hire me? Get in touch with me now!

Drupal Tut: User content in their own profiles

With Drupal being used for social networks more and more, there's a strong need to have Drupal displaying user content in their own profiles. You can use views to display a tab in a user's profile which will show their content. I'm going to show you how to make a tab to a user's images, "My Images" show up in their profile. We're going to take this a step further by using ImageCache to have thumbnails of the user's images specifically for this View.

You will need the following modules:

  1. Views
  2. CCK
  3. Views bonus pack (for grid display)
  4. Content Profile
  5. Image Cache

To start, We will assume that "Content Profile" has been set up, which will give users their own node for their user pages. User profiles will be accessed by going to www.site.com/user/[uid].

Also, we already have a content type of "Image" and we want to have a tab on the users' profile pages called "My Images" so we can list all their images.

Let's start by setting up an ImageCache preset to create thumbnails of images, and then using views to display all of a user's images.

1. Go to Site Building > ImageCache > Add Preset > name: Image_Thumbs > scale – set this to whatever you like

2. Now we'll create the view. Site building > Views > Add view > name: My_Images, type: node

3. Let's add the fields we'd like to show. Fields > Add >
Node: Title
Image: Image – Check off to "link this field to it's node" and choose the ImageCache preset you created from the drop down, "Image size to show"
Node: New Comments – label, "New Comments", "link this field to new comments"

4. Since we will make this display a list of all a user's images, let's set the style to "Grid"

5. In order to only show images of a certain type of content, we will filter the results. Go to Filters > Add > Node: Type = Image and make sure you add a filter to only show published images! Node: Published – Yes. Otherwise, you will show all images, published or not!

6. Arguments > Add > Uid. Keep the basic default validation.

7. Now for the magic! We created a view that displays only a specific user's images, but how do we create the little tab in their profile to show it? Those tabs are not part of the regular menu system in Drupal – those tabs are referred to as "local tasks." If you've tried adding things to those tabs, and you're new to Drupal, you've probably gotten very frustrated! Create a new display, for "Page," on the left hand side.

8. Where it says "path" on the bottom left side, enter user/%/myimages. This will use the user id argument we specified in the default display and pass it into the path. It will use the user's profile as the context for this page view.

9. To add the menu tab, click below "Path" where it says "Menu." Select "Menu Tab" and enter the title, "My Images" Update and save your view.

10. Now, all user profiles will have an extra tab called "My Images." You may want to add some empty text in the view, in case no images have been added.

Added bonus: Install lightbox2, and set up automatic handling of images linked to their node!

AttachmentSize
Views Export4.43 KB

Comments

Very helpful! Great post. Thank you.

This was a frequent request - glad you found it useful!

There seems to be a lot of relevent search engine traffic coming to this page, with only 1 comment? Was this article unclear? Would you like to see something else?

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options