By Littlebob on
Hi,
I need a menu item path to include a CCK value so that I can use it as a views argument. Any thoughts?
As a little more background, I am working on an alumni website and have a page listing all alumni sorted by class year. I want the page filter to default to only show the alumni in their specific class, not all members, which it currently does. If I can include the class year (CCK field) in the menu path, then I can use that as a filter.
Any help would be appreciated!
Thanks.
Comments
Views Arguments
Hi Bob,
You need to set up a views argument when editing your view.
1) Go to edit your view at /admin/build/views
2) Select the display that you are wanting to use (presumably a page?)
3) Click on path, and set it to something like 'alumni/%'. The percent means that's the part of the path where the year is going to go.
4) Now add an argument by clicking the '+' next to arguments.
5) Check the box next to 'Content: Year', or at least it should be called something very similar.
6) Set the options as desired and then click update. The default options should work fairly well.
7) Don't forget to save!
Now visiting the alumni/1990 page should give all alumni for which the year field is equal to 1990.
Hope this helps!
Dave Ingram - Gainesville, FL
www.ingraminnovation.com
Dave, thanks for the quick
Dave, thanks for the quick reply! The only problem is with step 5. The alumni year field is a CCK field and none of those show up. Any ideas?
And I just thought of one more issue. Is there any way to default to the current user's alumni year? For example, if I graduated in 1995, then going to /alumni would automatically bring up /alumni/1995?
Should be there
You should see it under 'Content' ..doesn't say anything about CCK, but it should be there.
For default arguments, select year as the argument, then in the box below, you'll see 'Action to take if argument is not present:'. Select 'Provide default argument', then under 'Default argument type:', select 'PHP code'.
Then you can do something like:
return $user['graduating_year'];
This is not right syntax, but if you figure out how to pull the right year through a PHP snippit, then this is where you'd put it.
Also, if you do this then change your path from 'alumni/%' to just 'alumni'. Views automatically receives arguments after the path, but if you put the percent then this view won't see the 'alumni' path, only something with a trailing slash and another argument.
Thanks for contributing this
I was trying to pass a custom user profile field to a view and was stuck for a couple of days until hitting this thread. With your little code snippet I was able to track down the correct syntax. Well, I don't know if it's really correct, but it works.
http://drupal.org/node/832304
global $user;
profile_load_profile($user);
return $user->profile_occupation;
It doesn't work for Content Profile
Hi Kevroc, are you using the native profile module in Drupal? I want to accomplish the same thing as Littlebob, but without any success after two-day searching and testing. I've tried lots of different php codes in the views' default argument including the one that helped you out. I am sure if it's because I am using Content Profile module.
I created a page view with a path of mysite/myspace and gave it a primary link on the front page, hoping when user A clicks it it would take the user to mysite/myspace/userA-content-profile-field-value page. It never works so far. A couple of other codes I have tried in the default argument php field are these:
Any thoughts would be appreciated.