Hello all,
I've got a dealine looming and still no further forward after 2 days of trying :o( Would love some help.
I have 3 pages on a site (/services, /blog, /news - using pathauto, and services, blog and news being 3 different content types). Each page contains a region, 'maincontent', which shows a view (the body of the page shows before the region).
The region currently contains a view which I'd like to show only the content type for that page (based on the URL) but I just can't work out how to use arguments. Everything I find online is about Views 1 and I'm stuck.
Is it possible to use an argument to say 'if the url contains /services, show only services nodes, if its /news show news, and the same for blog'.
I hope this makes sense. Thanks in advance.
Comments
=-=
http://mustardseedmedia.com/podcast/episode9 = A views2 videocast if you've not already seen it. I can recall if he went into arguments or not. I know he touched on relationships which is what I was trying to figure out at the time.
Thanks for the link. I
Thanks for the link. I watched the video but it only had the basics in there, never touched on arguments.
Doesw anyone know of any decent views 2 tutorials, podcasts or screencasts that may help me? I'm close to giving up and using straight php in the templates instead :o(
though the ui looks
though the ui looks different, afaik, the functionality of arguments is basically the same. did you try adding an argument of "node: type"?
===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz
Thank you. I have tried
Thank you. I have tried adding that. It works if I then use the preview at the bottom of the page on the views UI (IE I can filter by type using an argument) however it doesn't work on the actual page on the site.
Is this because my view is inside a region on the page, and not the page itself? eg /services is the URL for the page which contains the region / view. Pathauto is using /services to get the page which is perhaps why views can't see it, however /servces/services doesn't work either.
Grr.
Do you mean you're using a
Do you mean you're using a block view inside a block region? If yes, that's why the arguments aren't working-- block views require argument handling code to get the arguments to work properly on the page.
Try:
===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz
Sorry to be so ignorant. I
Sorry to be so ignorant. I can see what the code does, but where do I put it so that the view picks up on it?
Thanks again.
sorry-- i should have been
sorry-- i should have been more explicit. In your block view add the "Node: type" argument, then click on the link to configure it. Select "provide default argument" then "PHP code". Place the code in the "php argument code" text box.
===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz
Thanks again. That does not
Thanks again. That does not appear to work, although it's a step in the right direction. It is filtering the results, but showing all pages in every version of the view. Perhaps this is because /services is actualy the page containing the block / view, so the page 'type' is being returned?
Well, I got it working by
Well, I got it working by changing the return value from $node->type to $node->path. It works fine, but the only issue is that the page containing the block / view needs to use the name of the content type contained in the view if that makes sense. Feels a little bit of a cop-out to me...
Thanks a lot for your help.
hmmm... i would have
hmmm... i would have thought $node->type should have worked (assuming you have the url matching the machine name of the content type) but as long as you got it working. It's not really hack-- it's just not possible for blocks to get their arguments any other way. Somewhere in the views issue queue is an issue explaining that in a bit more detail.
and you're welcome ;-)
===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz
Use filters...
For what you are wanting, an easier option might have been to create three displays, which are filtered by content type, and then limit each display to only appear on the right pages... :)
Edit: This doesn't seem directly relevant to your particular query, but this tutorial I have posted might help others with related problems that end up at this page:
Limit Views-created block content by node author or current node