Drupal Tut: Content Profile Tabs
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 created specifically for this View.

You will need the following modules:
- Views
- CCK
- Views bonus pack (for grid display)
- Content Profile
- 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!
| Attachment | Size |
|---|---|
| Views Export | 4.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?
I think it was so clear that people didn't feel the need to ask questions! Great job.
The next thing I'd love to see is a post on theming the local tasks.
Thanks, Derek!
Sorry, I've got a question. Excellent post by the way! Every think works fine but when I click on the custom tab user name title desappears.. have you got any clue?
Thanks!
Hi Victor,
You may not be passing the argument in correctly - that's what will make sure you keep the user context.
Let me know if that helps!
Thanks! It was a silly thing, I just forgot set up the title parameter of the view
Ha! glad it's working! :)
is it possible to do subtabs? 1 more level underneath that menu tab that we just made?
E.g., In your example we just made a My Images tab that displays views. Is it possible to create another submenu underneath that that points to another view? (Say, My Cars, My Bikes)
Thank you kindly.
I figured out a workaround.
I didn't notice the Menu selection in the Panels dashboard. I created a new panel page and in content, i added a Quicktabs block.
Now if only we could use Horizonal Tabs as a main, and Vertical/Side Tabs as a secondary. (Theming maybe?)
ok spoke to soon. the quicktabs are suppose to pull in views that are user related. the normal view works fine.
in a quicktab, the view pulls in EVERYONE's data.
If you want to get that complicated, Panels would probably be your best bet. Then, create different views for each "sub tab" and use Panels to set up the main "My Images" tab.
thanks for the great post !!
Awesome post! You paid attention to details, that's a good thing, makes it a lot easier to understand. One question, this tab appears in every user pages, but is there a way to restrict the tab to appear in only in user's own page?
If you've set up the arguments correctly, the tab will only show a user's own posts.
You can optionally use Panels to set up a more complex view, and only display it for the logged in user viewing his own profile.
Thanks for reading!
Awesome tutorial! Used this to create a "my content" tab for writers to view and edit their content!
A very nice tutorial on a very useful feature. Together with this tutorial on how to build dynamic views, by Matt Petrowsky, the possibilities are endless.
-Patrik
How would I use this for the Blog Module? I want to create a tab to show all of the users blog posts. I tried following your tutorial and filling in the blanks for the blog, but no avail :(
Dillon,
It should work no problem if you just change the content type for your view to "Blog post" instead of "Image."
jaxpax,
thanks for sharing the tutorial! Views arguments are really complex, but super powerful!
This was an awesome tip, I wasn't trying to do the same thing (tried to use content profile and make an extra tab under the profile to display this page) using the same basics this worked like a charm. Extremely hard to find informatin about this.
Very very Thanks for your kind teaching. I saved my times.
Awesome! Thanks for sharing this tutorial! ... Sure saves me wracking my head against the wall any longer!
This Rocks! Thanks!
Post new comment