Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal 7 View to list content created by logged in user

Tags:

views

drupal

I've just started using D7 and was trying to set up a system where people can add a couple types of content and associate one with the other via nodereference.

I only want users to be able to see and work with their own content.

To achieve this in D6 I used a view for nodereference.

In D6 I used argument : user: uid and if there is no arg, it uses the user id of the logged in user. This would return all of the content that was authored by the user.

I haven't been able to figure out how to do this in Views 3?

got it: you first need to add a User relationship, then you will see new filters and contextual filters - one of which is "current user" or something like that

like image 271
Justin Avatar asked Dec 21 '22 10:12

Justin


2 Answers

This five minute video shows how to do it, as well: http://nodeone.se/sv/node/684

With contextual filters you can also display the list as a tab on each user page (as shown in the screencast).

If you're interested in a list that always shows the current user's posts, you can use a standard filter instead – there is a "current user" filter available.

Edited: The original link is broken. I'm not sure which video it was, but it could be one of the following (which all deal with this topic).

  • https://vimeo.com/22276809 Video guide
  • https://vimeo.com/33588889 Exercise description
  • https://vimeo.com/33588956 Exercise solution
like image 87
Itangalo Avatar answered Dec 31 '22 15:12

Itangalo


For drupal 7

Steps for doing as the above question are

  • Create a new content view and limit it to the content type you want.
  • Uncheck "Create a page" and check "Create a block." Select the format you want; I recommend an HTML list of linked titles. Click "Continue & edit."
  • Add a contextual filter for "Content: Author uid."
    • Under "When the filter value is not available," select "Provide a default value," and select "User ID from URL" from the dropdown. Because blocks don't understand contextual filters very well, the view won't work properly without this default value, and all posts of the given content type will show on all user pages (not just the user's own posts).
    • Under "When the filter value is available or a default is provided," check "Specify validation criteria" and select "Basic validation" as the validator. Select "Hide view" from the dropdown.

  • Save your view.
  • Assuming that you created a block display, the block will now be available on the Blocks page. Go there and open it.
  • Set your block to display on all user pages (/user/*) in the correct region. Save the block.
  • Your block should now appear on all user pages, showing the content written by each user.
  • Source

    like image 29
    RAHUL KUMAR Avatar answered Dec 31 '22 15:12

    RAHUL KUMAR