2

I have a block on the user's profile page that filters content based on the supplied tag as an argument/contextual filter. Users on my site can add tags to their profile (with an autofill field pulling from the free-tag taxonomy) -- these tags are topics that they want to "follow." I would like this block to display content that is tagged with the tags they've personally chosen. thanks in advance!

  • I like how you exposed your problem in a very clear and consistent way, plus, I like the question itself! 1+ – amateur barista Mar 20 '12 at 4:40
  • BTW, specifying the Drupal version on your question is very important in order for users to provide you with the most accurate information. – amateur barista Mar 20 '12 at 4:51
  • I am using Drupal 7. – craigritchie Mar 21 '12 at 1:34
1

I have found a solution to this. Using a user view instead of a content view was the way to go for me. Then adding appropriate relationships on the teaxonomy term.

I used the these directions:

  • Create a user view.
  • Add a contextual filter on user: uid. If no filter value is present, build a default value using the currently logged in user. (This will give you exactly one user object in your view -- the logged in user.)
  • Add a relationship, using the relevant taxonomy reference field on the user accounts. This will bring you information about the "interest" term for the logged in user.
  • Add another relationship, called "term: nodes marked with term" (or something like that). This will bring you information about all nodes marked with the interest term for the logged in user.

From this article: https://drupal.org/node/1111722

Hope it helps!

0

I have not done this before, but I would try doing the following first:

  1. Define a View. Make sure the type of View is "user" and not the default "node".
  2. Define fields. If you are using Drupal seven, read the article on working with content types and fields:

    Fields on user accounts are defined on a site-wide basis on the Manage fields tab of the Account settings page. When you define a field for user accounts, each user account will have that field added to it. For example, you could add a long text field to allow users to include a biography.

  3. Once you've defined those fields, add them to your View and create a block display within your View. Save your View.
  4. Add your View block to any of the regions appearing on your /user page.

  • This doesn't make sense to me. I want the block to list content/nodes that are tagged with the tags that the authenticated user has chosen. Not a list of users... – craigritchie Mar 21 '12 at 1:36
  • My rationale is that if you define fields in the user profile, to retrieve the contents of those fields you must create a view of type user, and pass down to the view as a contextual filter the current user. Then you could use the results of that View (the user tags) to construct your contextual news block. Now as you can see this solution starts to get fuzzy here if you limit yourself to use "tags defined in their profile". Have you considered using flags? You can have user-based flags, and filter by those on your View. Your approach would be OK in a D6 world, but in D7 flag are the way to go – amateur barista Mar 21 '12 at 19:12
0

You should use hook_user_load

You load the user variables with the array of the tags.

Then you need view_embed_view to print the view in the block.

print views_embed_view('my_contents', $display_id = 'page', HERE THE CONTEXTUAL FILTERS )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.