Hi,
This would be absolutely stunning if I could make this work :)
I would like blocks to show that are based on the user (content_profile)'s selected terms.
So basically load view related to taxonomy term selected by the user.
The following works perfectly as a related view based on the current node taxonomy term:
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node=node_load(arg(1));
return implode('+', array_keys($node->taxonomy));
} else {
return FALSE;
}
I've tried if (arg(0) == 'user' && is_numeric(arg(1))) {
Would most appreciate if anyone has found the solution to this.
Lilian
Comments
Comment #1
dawehnerIts not tested, but should work.
Comment #2
liliplanet commentedOh my goodness dereine, do you think it is possible?
I've tried the above as a default argument in my view as follows:
but unfortunately does not work .. I would be more than appreciative for further help on this, it would change the content of my site completely.
Look forward to hearing from you.
Lilian
Comment #3
liliplanet commentedI'm including the export of the view .. thank you so much :)
Comment #4
liliplanet commentedsorry, attached updated view
Comment #5
liliplanet commentedYes! Deriene, I almost got it to work. Please, now it only loads on the users content profile page, but I would like it everywhere on the site.
I will exclude pages in the block config.
This is so stunning!
Look most forward to hearing from you, and thank you so much!
Comment #6
liliplanet commentedAnyone please? How do I show:
on all pages on the site, and not just the content profile. How I wish I knew more ..
Update: also if the taxonomy could only load by a certain vocabulary, in this case 'country'.
Thank you for any help.
Lilian
Comment #7
dawehnerAs far as i understand the thing is for the current user. Thats quite easy to make.
This should work for the current user.
To filter by vocab, replace $node->taxonomy with
foreach ($node->taxonomy as $key => $term) {
if ($term->vid == $vid) {
$array[$key] = $term;
}
}
return implode("+", $array);
Comment #8
liliplanet commentedHi Dereine,
Wow, this is absolutely fantastic, thank you!
Just a slight problem, when a user is tagged by 2 vocabularies, the results appear twice, for instance if user is tagged with South Africa (country) and Cape Town (city) .. and the result of the other content type is also tagged with the same country and city.
Is it possible that the argument filters by only 1 vocabulary please? Which would be country and vocabulary id = 1.
Most appreciate this amazing enhancement :)
Look most forward to your reply.
Lilian
Attached picture of where the user is tagged South Africa + Cape Town and the job offer is also tagged South Africa + Cape Town
Comment #9
dawehnerThe duplicate stuff, could be perhaps solved by using duplicate setting in views.
The other thing did i wrote:
Comment #10
liliplanet commentedHi Dereine,
If I could only express how appreciate I am of your very kind help.
When adding #9 .. I get the following error:
and when I return to the previous code #7, all is well. Also no duplication :)
Just a last question please .. I'm wondering the code in #9, would it have less queries than #7?
Which of the 2 would be optimal for loading the associated country content?
Dereine, this has made a major difference to my site, thank you so so much.
Comment #11
dawehnerups
I currently don't really know you setup so i cannot answer which is optimal, but less terms in the sql should be always better.
Comment #12
liliplanet commentedWow! that is stunning, so much appreciated Dereine :)
Really promise, last question, which has the less queries, #7 or #11 as both work wonderfully ..
Thank you Dereine.
Comment #13
dawehnerso this is fixed.
Comment #14
liliplanet commentedYou are super-star! Thank you Dereine :)
Made a major difference to my site, and hope to launch soon.
Thank you again ..
Comment #15
Bilmar commentedHello,
I have been looking for something like this forever! I appreciate your work.
I am very new to drupal and require a little more assistance if someone could please provide (I was not able to do the above).
I created a content profile for users with taxonomy terms selected to the profile.
I made a Views page and would like to do the same as above - have the Views page filter depending on taxonomy terms selected on current user's profile.
Could someone please assist?
Thank you very much in advance!
Comment #16
liliplanet commentedHi trupal218,
First of all I'm using Content Profile and my content type is called 'profile'.
Create a block with the following:
Create an Argument Taxonomy ID
Action to take if argument is not present >> Provide Default Argument
Provide default argument options >> PHP Code
Add this to the PHP Code
Validator >> Basic Validation
Action to take if argument does not validate: Hide View
Save ..
Look in admin/build/block to add it where you want it on your site.
Comment #17
Bilmar commentedWow - thank you very much for the quick reply!
I have successfully created a view with argument that pulls taxonomy terms from current user's profile!
If you may have time:
As of now I have to go to the Profile Edit page each time to change my selection, then return to the Views page to see the results.
Q) Is it possible to create a block or (even better) a pull down menu on the search page where I can change my selection (which I chose on my profile edit page)?
Thank you very much!
Comment #18
liliplanet commentedHi Trupal,
The blocks will show dependent on on the user's choice of their country. So it's what they chose as a term on their profile.
Now if you want to show content by term related to the node, iow if the node is example Canada, all blocks next to it will show content related to Canada.
The same as above, but add in the php
It will only show on node/*
Also have a look at http://drupal.org/node/323329
Comment #19
Bilmar commentedThanks again for the quick reply and I have been looking at many screencasts and reading guides to better understand Drupal and php =)
To better explain what I am trying to achieve:
- I have Content Profiles that user's create (worker profile & company profile).
- I use Content Taxonomy to tag the user with the fields they select.
- On the Search page I want to have the View automatically filter by what was select as preference in Profile setup (which you helped me achieve!!)
(**now trying to achieve) I also want to be able to edit the profile fields from the Search page to refresh the results (so you don't have to go back and forth). Making changes on the Search page should make changes on the profile edit page as well as they should be the same field.
I'm having a great time learning Drupal and really appreciate the support!
Thank you very much in advance!
Comment #20
liliplanet commentedNo idea how to change terms on a search page.
If you give users the ability to change (all terms), then try http://drupal.org/project/views_bulk_operations
Comment #21
Bilmar commentedoh man, your response time is amazing!!
thanks for your help - I will continue to go deeper into learning Drupal =)
Comment #22
Bilmar commentedI'm sorry to come back again with another question.
With the code you provided below, would it be easy to change to only load taxonomy terms from specific vocaublaries (ie vid=1 and vid=2)?
Thank you!
$type = 'profile';
global $user;
$account = $user;
if ($node = content_profile_load($type, $account->uid)) {
return implode('+', array_keys($node->taxonomy));
}
else {
return FALSE;
}
Comment #23
liliplanet commentedit has already been answered by wonderful Dereine, read #9 on this thread ..
replace vid == 1) with the id of your term.
Comment #24
Bilmar commentedThank you very much!