I really feel dumb asking so many questions..

but here is my question..

what if we have a url in drupal that looks something like this

www.mysite.com/Music/Artist/Western

can someone please tell me how to grab the third argument in that URL (which is Western)

and use it as a variable in php code of a contemplate..

does that make sense...

please let me know if I need to explain a little more

Comments

benwei’s picture

I think the thing you're looking for is the arg() function. It takes a single argument, which is the index of the argument you want to retrieve from the URL. Documentation can be found here on api.drupal.org (a great resource if you're not already familiar with it).

In your example, you would want arg(2). arg(0) would be Music, arg(1) would be Artist, and arg(2) would be Western.

Cheers,
Ben

Oghnia’s picture

I did that but it looks like when I put

<php print arg(0) ?>
I get "node" as an output

<php print arg(1) ?>
I get "1" as an output

<php print arg(2) ?>
I get nothing as an output (nothing gets displayed)

am I doing something wrong?
______________________________
next project convert this site to drupal -> http://www.oghnia.com

marcvangend’s picture

arg() only works with the real url, not with the path alias. For instance, if the url is node/12 and the alias is page/welcome, arg(1) will return "12", not "welcome".
I just found this node in the handbooks: http://drupal.org/node/117491. Maybe that solves your problem?

sharri_bgood’s picture

$args = preg_split('/\//',$_SERVER['REQUEST_URI'],-1,PREG_SPLIT_NO_EMPTY);
print_r($args);
Oghnia’s picture

OK just to update everybody
this works

$path_pieces = explode('/', drupal_get_path_alias($_GET['q']));
then you use this to select which part of the URL you want to use (0, 1, 2 etc)
$path_pieces[2]

anyway..

now,, what if your page belongs to 2 or 3 different taxonomy terms how do you display all of them in the url

www.mysite.com/Music/Artist/Western/Pop

how to you display [Pop] there....
right now I am using the following pathauto logic
Music/[title-raw]/[term-raw]

now [term-raw] stands for the taxonomy term,, now for the second taxonomy term should it be [term-raw-1] or this doesn't make sense?

______________________________
next project convert this site to drupal -> http://www.oghnia.com

marcvangend’s picture

Why would you want to put all taxonomy terms in the url? Are you trying to pass the terms to another element on the page, like a block?

If your goal is to do something with those taxonomy terms in a block, I think you'd better take another approach. When you get the nid of the current node, you can get the node object from the database using $node = node_load(). This node object will contain all taxonomy terms you need.