Thank You for your help.
I'm trying to create a view that will only display nodes if their taxonomy term name matches the current url.

For example, a node with the taxonomy term name "sports" will be displayed only if the current url is "www.example.com/sports"

Something like this pseudo code:

<?php
//set the vocabulaty id number
$vid = 3;

//get the current url
$uri_request_id = $_SERVER['REQUEST_URI'];
$section = explode("/", $uri_request_id);

//do the camparison
if ($section[1] == any of the term names in the vocabulary? ) 
show the node; 
else
don't show the node;
?>

Is this something you can do in the Argument Handling Code?

Thanks again,
Scott

Comments

drawk’s picture

You shouldn't need to use the argument handling code. Instead, under Arguments, add the argument "Taxonomy: Term Name" and in the 'Optiion' textfield, enter 0. (From the help: 'For this argument, set the option to the number of characters, using 0 for full term; use 1 for an A/B/C style glossary.')

Sc0tt’s picture

drawk, I've looked at that argument and and I don't understand how to compare the term names to the url. Do I insert something into the wildcard field?

Thanks again,
Scott

PS. I'm using...
Drupal v5.7
MySQL v4.1.22
PHP v5.2.5
Apache v1.3.37 (Unix)
url www.fillmoregazette.com

drawk’s picture

You don't really need to do anything except to add it. Views handles the arguments from the url in the order that you list argument handlers. So by adding "Taxonomy: Term Name" as the first argument handler, this will make it so the first url component after the view name will be treated as a taxonomy term to filter the nodes with.

So for yoururl.com/viewname/golf Views will treat "golf" as the first argument, and since you've added Taxonomy: Term Name as your argument handler, it will only show nodes with the term "golf" applied.

Sc0tt’s picture

drawk, it's almost working...

It is displaying nodes based on their Taxonomy: Term Name; but it doesn't seem to be paying attention to the url. You mentioned in your last comment that the url the argument would look at "yoururl.com/viewname/golf"; but my url's are "yoururl.com/golf" without the viewname. Do i need to specify somehow to use the first name after the root url?

Thanks again!
Scott

PS. I'm using...
Drupal v5.7
MySQL v4.1.22
PHP v5.2.5
Apache v1.3.37 (Unix)
url www.fillmoregazette.com

drawk’s picture

Scott, is this a page view or a block view? Also, what version of Drupal?

I'd assumed a page view. If a block, you will need to use a bit of argument handling code. You can add something like "$args[0] = arg(1);" to the argument code textarea and that should do it.

Sc0tt’s picture

The view with the argument is generating a BLOCK; but the current url is another view that is a PAGE view. Perhaps that's the problem? I'm trying to look at another view's url?

I'm using Drupal v5.7

Thank you,
Scott

drawk’s picture

Scott, I edited my last post after I first sent it and think we may have crossed. Give the argument handling code a try and let me know if that works out for you

Sc0tt’s picture

drawk, I tried adding $args[0] = arg(1); to the Argument Handling Code; but the results of the view didn't change. It still seems to be ignoring the url path.

EDIT: you can see a screenshot at http://www.fillmoregazette.com/xxx-test-page/view-screenshot

The view is generating a block that I am placing on a page that is another view's page view. Does the argument care from what view the url is generated from?

Thank you,
Scott

PS. I'm using...
Drupal v5.7
MySQL v4.1.22
PHP v5.2.5
Apache v1.3.37 (Unix)
url www.fillmoregazette.com

drawk’s picture

Hmm, it could be because the block view is rendered inside of a page view, although arg(1) should still be available so I'm not too sure why the argument handling code would fail in that case. Unfortunately, I'm just not sure why that isn't working. Anyone?

gregbeat’s picture

Let's say you've got a page with a block view on it. If you name the page the same as the taxonomy term, you can do this:

$node = node_load(arg(1));
$args[0] = $node->title;

For my latest scenario, I didn't want to name the node the same as my tax term, so I went about it this way:

//arg1 returns the node id, so I create a path and get the alias (my path-auto path)
//note: in my case the path is always "node/nodeid" so I can get away with hard-coding the first part of the path
$temp = drupal_lookup_path("alias","node/".arg(1));

//in my case it will return something like "directorya/directoryb/destination"
//so we want to stick it into an array
$arr_temp = explode("/", $temp);

//grab the destination (PHP "end" function grabs last value in array)
//do a little cleanup in case it's two words (you can perform whatever may work for your situation with whatever PHP string function you find appropriate)

$myterm = str_replace("-"," ",end($arr_temp));
$args[0] = $myterm;