Good afternoon all.
I'm trying to figure out how to do something in Views 2 using arguments, but am having trouble figuring it out. I've searched, but haven't found a good tutorial. The documentation assumes an understanding of arguments...which I don't have yet.
What I want to do, is create a view which displays all nodes of a certain content type, and dynamically display only nodes which have their "state" fields completed by the state in the url.
So, let's say I have nodes of thousands of doctors. Eash node (a doctor) has fields for city and state. I want to have a view for "California" which would display all of the cities (in California) which there are nodes for, and the url would be domainname.com/california.
Drilling further, I want a view which dynmically pulls the city, and would make the URL domainname.com/california/los-angeles. And that would display all nodes which the state and city fields equals "California"/"Los Angeles".
Obviously, since the number of cities is massive, I would want to be able to do this with 2 views (one for state and one for cities). I believe (stress "believe") this could be done with arguments...true? If so, any help is hugely appreciated.
Dan
Comments
_
Yes, this is exactly the kind of thing views arguments are designed for. What you are seeking is essentially descibed in the Creating Hackable URLs (Index Aliases) Using Pathauto and Views screencast. It's for d5, so the ui looks a bit different, but the concepts are the same.
Basically, you'll want to create a view with a filter for the content type you used for your doctors, then add arguments for state and city. Depending on whether you used taxonomy or cck fields, the exact argument you pick will be different but they should be easily found in the "arguments" settings box on the views configuration form.
I'll take a look at that
I'll take a look at that tonight, thanks!
I'll return with questions/feedback/praise/paypal money :)
I have similar but slighly different problem
Good day
maybe someone could point me to the right direction.
I use drupal 6.10, views2 and cck.
I try to setup a pretty simple site. Just 2 content types: article and author.
Author is different from user - in fact I am the only user, but there are multiple authors.
In 'author' content type I have author's name field named 'author_name'.
Then I have 2 views: author_profile and list_of_authors.
In 'article' content type I have 'author_name' field as node reference and I use 'list_of_authors' view to select an author of this particular article.
So I have a front page - a list of articles. Every article has a title, a body and an author.
If I click an author it gets me to a page of this author. If displays author's name and some bio information.
Now that's where problem starts.
I want to put under a block which displays list of articles of this autor /just article titles/.
Seems simple but it's beyond me. After tons of googling and reading and hours of experimenting /some of them completely wild/ the best I can do is display of all articles of all authors.
In detail:
I have a view called 'author_profile'.
Display is default and block.
In filters:
node: type=article.
In relationship:
Content: author_name - (field_author_name)
In arguments:
Content: author_name - (field_author_name)
use relationship author_name
In fields:
Node title.
All of this gives me exactly what I want in live preview provided I put argument /say "Smith'/ inside.
The block has a name: author_articles
I can manage to display this block just only where I want - on authors page.
What I can't do: I don't know how to display only articles of presented author. /As said it displays all articles of all authors/
I need to convince drupal that is should take an argument to this block from a field above called author_name.
Probably in view, in validator php code I need something similar to:
$argument=field_author_name_value
but my expertise on this is very low. Any other direction of solution is welcome but autopath is exluded.
Anyone can offer an advise?
Yorr
PS Excuse my basic english.
Shouldn't be that
Shouldn't be that hard.
"create a view which displays all nodes of a certain content type"
That should always go into a filter. I assume you know how to do that.
"domainname.com/california/los-angeles"
You can't do that. You will have to use something like "locations" in the Path field (in Page settings). Unfortunately, Views does not allow to use an argument as the first part of the path in the URL. It'll have to be something like "domainname.com/locations/california/los-angeles", where locations is static, cali is the 1st argument and LA is the 2nd.
So that's always domain/fixedstring/arg1/arg2/...
"and the url would be domainname.com/california"
Again, can't be done for pretty much the same reason.
"I would want to be able to do this with 2 views (one for state and one for cities)"
You can do this with only 1 view and only 1 display (a page display).
"I believe (stress "believe") this could be done with arguments...true?"
Yeah. Right now I have something urgent to do, but I'll try and outline how I would try to do it in a minute. Watch this space ...
:-)
Oops
I just saw the answer above after summitting. My comments are still valid, though.
Haven't seen that screencast, but I'll leave it with you to play around.
hmmm....ok. My question,
hmmm....ok. My question, then, would be how can I go about creating what I need and keep the URL structure I want? Without having to create views (without arguments) for every city (way too much).
Would it work to create a view for the state pages that doesn't use arguments, and then create 50 views (one for each state, with arguments) to display the doctors within each city, and start the path with the state name (followed by the argument for city)? Does that make sense? It's 100 views, which wouldn't be fun, but the URL structure is important to me.
Thanks,
Dan
_
You might be able to get the effect you want by creating a basic node to serve as the home page (assigned at admin/settings/site-information) and then just use code to embed the view into the page (using the php code input format). There's documentation in views advanced help for the code to embed a view.
"I'll try and outline how I
re: frames: "I'll try and outline how I would try to do it in a minute"
If you could do a walkthrough I would appreciate it. I find the documentation lacking, like I said, it seems to assume you already have an understanding of arguments, which I don't. I don't know what to place in the argument fields, what options to select, and how to translate that to dynamic paths and titles... In looking around it appears I'm not the only one. So if I can figure it out maybe I'll write something up for argument newbies like myself.
Thanks again.
Dan
_
1) do you have a view already created?
2) how have you implemented states and cities? Taxonomy? CCK?
Yes and yes :)
Yes and yes :)
_
um... #2 is not a yes or no question, lol. I can't tell you what arguments to use if I don't know how you created the state and city values on your nodes. ;-)
Sorry, read too quickly. I
Sorry, read too quickly.
I have implemented them as CCK fields. I'm still trying deciding on the best way to go about creating this site, so I may end up changing it to taxonomy instead.
D
I'd go with taxonomies,
I'd go with taxonomies, unless there's a way to create hierarchies in CCK (which I don't know).
If you use taxonomies I believe you can create two args, one (cities, the second one) dependng on the other (states, the first one). Let me double-check to see if that's poss.
thx
Great to see this thread -- i actually need Exactly the same thing.
AgentD have you had any success?
I have
This is one possible implementation.
First off, you want to have a taxonomy with States and cities. Cities must have their respective states as parents.
Then go to Views and ...
Add View- I used "places" as view name, description and tag (but doesn't matter)
View type: Term
Add display Page
Basic settings:
- Title: States
- Row style: Fields
- Use pager and items per page as needed
Page settings:
- Path= places (or whatever you fancy)
- Menu= you could use one
Relationships: add Taxonomy: Parent term
Add argument: Taxonomy: Term (twice)
First argument:
- Relationship: parent
- Title: States in %1
- Action: Summary, sorted ascending
- Validator options:
-- Vocab (the one you used for this)
-- Argument typ: Term name or synonym
I used a style list for the 1st one.
Second argument:
- Do not use relationship
- Title: Citi
- Action to take ... Display all values
- Validator: same as before
Fields: Taxonomy: Term
- Do not use relationship
- Link this field to its taxonomy term page
Frames you are the bomb.
Frames, thank you so much for writing out these steps.... we are so close to having things working now because of your help.
Right now the way things are functioning is that i get a list of Parent terms (Summary, sorted ascending), which i click and it takes me to a list of children terms.
We are using the Taxonomy Module and out goal is to use each parent term's Taxonomy Image rather than a text link.
I have tried a couple things with no luck... doing the following got us close but still no good.
Fail:
- Added Field:
Taxonomy: Term image Term image
- Change Argument 1 to "Display All Values"
Failed Result: A Taxonomy Image prints for every single term (not just the Parent terms as expected)
Any ideas?
thank you!
I don't know why, but I think
I don't know why, but I think the problem is that you have gotten rid of the "Summary, sorted ascending" in the 1st argument.
I tried adding a filter with "Taxonomy: Vocabulary", but it'll display all the states an cities, so I'm afraid you'll have to stick to the original selections. I don't know how that behaves with the images, though.
Frames, You are correct; if
Frames,
You are correct; if i get rid of "Summary, sorted ascending" in the 1st argument this will cause my problems.
Do you know if it's possible for me to modify the way that the "Summary" is printed out?
thank you.
I'm out of ideas here. You
I'm out of ideas here. You might have a module I have not tried yet. Maybe Taxonomy Image?
If so, in its page you'll see:
Add Views argument support. 5.x only
So unfortunately it looks as if argument support in 6 for this is missing/limited, or at least what you want to do is missing in Views2 (D6).
I'll give this a try, the
I'll give this a try, the very least it'll help me understand arguments more.
I think what I'm going to end up doing is making 100 views (one for each state which displays the cities of each, and one for each state which uses arguments to display the nodes for each city). That way I can work around the requirement to start a path for an argument with something other than "%" (I can start the path for the cities of california view with "california", etc.). It's a lot of views, but still better than alternatives.
Thanks again.
D
Ok, I think I actually got it
Ok, I think I actually got it to work!
Now here's a slight variation I want to throw out there to see if it can be done, because I'm still looking for a way to make this work with the URL structure I want (that being one without starting the path with something like "places" that you used, as an example).
I realized that I don't really need to make a view for cities when the cities are terms, because the core taxonomy package will display the nodes that have that term anyway. So, what I need to be able to do is create 50 views, one for each state, which displays that state's (parent terms) cities (child terms).
I tried tweaking what you provided in order to achieve this, but I'm still not really understanding all the options within arguments. So, how can I create a view with a path of "california" and tell it to display child terms of the term "california"? I didn't see any option with Relationships or Filters to say "only show child terms of: ____ "
Is that possible?
Thanks again frames for your help!
Dan
In "Relationships: add
In "Relationships: add Taxonomy: Parent term" in the 1st argument and "Relationship: parent" also in 1st arg. That should do the magic.
If you're only using one argument ... I just don't know.
I don't get the 2nd argument.
I don't get the 2nd argument. It works same with or without it. What's the use of it?
I have created taxonomy (Drupal 6.10):
Printers (vocabulary)
--Laser printers (term)
---A4 printers (subterm)
On generated page it displays "Laser printers" (without nodes listed). Click on that link goes to page "A4 printers" (without nodes listed) and after that to taxonomy page with nodes.
Also did not find
- Validator options:
-- Vocab (the one you used for this)
There is only Node, PHP code, Taxonomy term, User validators for this view type. I have used Taxonomy term - Vocabularies. Is that it?
Am I missing something? Can somebody explain 2nd argument?
Sasha
Print & Screen
Thread of the year :)
Finally argument-related information which makes me understand how to work with them. Thx!