1

I have a profile page for each user where it will show all nodes he has created for each content type.

For instance, Autos content type will only list all autos he has authored. I'd like to be able for the user to access it using this path : http://localhost/mysite/myreports/autos and will show his autos, .../myreports/jobs will show his job postings, .../myreports/events for events etc...

I have tried doing it in views using page views with path ..../myreports/% (where argument is the name of the content type) and added a views contextual filter for 'content type' but i cannot get it to work.

I had read this : Drupal 7 Views Contextual Filter to show only nodes of the same type but it's not working.

I can set up each unique view to a content type without using contextual filters so I can specifiy a permanent url for say ...myreports/autos but then that would be inefficient.

Any suggestions?

3

After hours of tinkering here is my solution to the above. If anyone has the same requirement this will help:

Drupal 7.16, views-7.x-3.5

The View Setup : enter image description here

The result (sample 1):

enter image description here

Sample 2: enter image description here

No other settings required. Even in the section "WHEN THE FILTER VALUE IS NOT IN THE URL" does not matter, what seems to be important is you set the validation to always return TRUE regardless.

The path of this view is set to /myreports/%

Perhaps, the filter value in the URL that was found will be validated to always true. Then resolves to using this as a normal filter, as is the case with the normal filter setting. Hence, Filter content type = events (or jobs).

1

Add contextual filter as content type and set value from url path. See screenshots.

enter image description here

enter image description here

  • Thanks for taking the time to answer my question. And yes I did what you have suggested. Raw value from URL but still does not work. After hours of tinkering I found the solution myself which I will be posting here for everyone to check out. This is particularly useful if you want to show 'reports' type page for each content type the users has posted. – jan Dec 21 '12 at 8:38
0

The problem with the previous solution is that it will not work for Content Types that have more than one name such as "Press Releases". This worked for me

  1. For Context Filter, select Content Type.
  2. Select "Provide Default Value" and select "PHP Code".
  3. Enter the following snippet of code:

    $node = node_load(arg(1)); echo $node->type;

  • The previous solution worked for me even with multiple-word content type names. I just used the machine name in the argument, e.g. "press_releases". – pushka Sep 10 '15 at 9:17

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.