I am new to Drupal and have a website with content from different schools. I made a taxonomy vocabulary "school" with the terms being the names of the different schools. Each school has its own page at www.example.com/schoolname1, www.example.com/schoolname2, etc. I want to have a view on each www.example.com/schoolname page that will display stories that are from that school only. I want just one view that will automatically figure out what to display, not a bunch of separate views that are school-specific, as this will clutter up my site. After trying to figure it out I think it has something to do with Views arguments but I don't know how to set it up on my site -- the basic help info for Views didn't do it for me either. Can someone please help? Thank you!!!
Comments
.
Hi,
Yes, you're right, it does have to do with the Views Arguments.
I don't know of any extended tutorials for this off the top of my head (although they are probably out there somewhere), but the two main places within Views where you can you set this up would be in the Filters section and Arguments section. So, under Arguments, you can add Taxonomy Term and point it to the right vocabulary set. Under Filters, you can add Taxonomy Term again without selecting the specific term. Then the filter should work with Arguments to display the correct information.
This is just a short summary - there are quite a few settings under Arguments, etc. I'm still a bit in "holiday mode" right now :-) so I can't remember if this is what of the instances in which you would need to provide some PHP code under Arguments to make it work correctly / work with path alias. Perhaps someone else can come along and clarify this part. But it's definitely possible to do all of this within Views - I do the same thing for the same reason.
_
Actually, filters and arguments work independently of each other. if you want a permanent filter for the view you use filters, if you want interactive filters (via the url) you use arguments. For a good screencast see http://gotdrupal.com/videos/drupal-views-arguments.
.
So you're saying that in a case like this, you would create the argument and then not bother with the filter section at all? If that's the case, that is good to know because it means I've been adding an unnecessary step.
_
It depends-- if i wanted the view to always be stories, then i would use a filter for node type story and an argument for the taxonomy. Use filters for criteria you want to always apply to the view, and arguments for filters to be selectable via the URL.
.
Ok, but what you were saying earlier is that when using arguments, the corresponding field doesn't need to be used in filters, right?
_
nope.
.
Interesting. Thanks.
what settings?
thanks for the help so far -- what settings should i be using for the argument? i looked at the screencast but it looks like that focused on an argument based on the user ID, not a taxonomy term. how do i set the arguments up for my case?
another issue is that i don't have the school pages grouped together in a "school" argument, like example.com/school/example1 and example.com/school/example2. i only have example.com/example1 and example.com/example2.
also, i want to display the view as a block, not a page.
thanks!
.
So each school is a term - you can still use Views arguments. You can modify the URL structure as needed - are you using Pathauto?
You can do this in a block display instead of a page display - although if I remember correctly, you will need to add some PHP code and tweak it a little in order to do this in a block.
.
yes I am using Pathauto. i'm guessing this makes it more complicated?
.
No, not at all. Pathauto should make it easier. Because, among other things, if you wanted to go back and change the URL structure, you can do a bulk update.
.
So if you're going to have a block display, you can add Taxonomy Term in Arguments, and then choose to "Provide default argument".
And then if you were to change the URL structure for this part of the site to have example.com/school/SchoolName, you could add something like this a the default argument in Views:
.
would there be a way for the view to still show up on example.com/SchoolName? i.e. can i then alias example.com/SchoolName in place of example.com/school/SchoolName?
.
Someone else will need to jump in to answer this part better. I want to say doing that is going to cause some problems, but I'm not sure that I can explain it very well at the moment. I don't know what else you have on the site, but without isolating this View to a specific set of paths, it will be evaluated for every page. I don't know if Views will work / allow this in the block display. With page displays, it won't let you put an argument in the first segment of the path.
What about a deeper path?
Hi,
What if I want to display something on http://www.example.com/school/utaustin/example-article? this would be a deeper level of arguments (would it be considered $path[2]???? How would I change the PHP code to have the view show up on that article page?
Please help!!