Community & Support

Getting a node's URL alias from Views

I would like to get the raw URLs of the nodes collected in my Views query. I can't seem to find a Field that is devoted to this purpose.

Yes, there is a node link field, but I need the raw URL itself to pass it into a multimedia piece.

Yes, I can grab the nid and scrap together a working URL but I would much rather use the URL alias.

Is there:
1) some sort of a Drupal function that will output a URL alias if I pass it the NID?
2) a field I'm just not seeing withing the Views Fields that will yield the URL alias?

Thanks so much for your time!

Edited by WorldFallz - moved to appropriate forum.

Comments

_

you could probably get this working by using drupal_get_path_alias in a http://drupal.org/project/views_customfield.

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.

Thank you!

Thank you!

I am using a tpl.php to theme the View so I just inserted the function call in the markup... didn't even need the customField module, although it's great to know it exists.

For anyone else using a tpl.php the code I used to grab to correct alias looked like the following:

$targetPath = "node/";
$targetPath .= $row->nid;
$targetPath = 'http://'.$_SERVER['HTTP_HOST'].base_path().drupal_get_path_alias($targetPath, $path_language = '');

Sorry I posted in the wrong forum. I just thought this was theming related.

Thanks Ecksley, i needed just

Thanks Ecksley, i needed just that to do something similar...

Good info! Thanks.

Good info! Thanks.

In case someone does want to

In case someone does want to output url_alias in views using customfield php

<?php
$targetPath
= "node/";
$targetPath .= $data->nid;
$targetPath = 'http://'.$_SERVER['HTTP_HOST'].base_path().drupal_get_path_alias($targetPath, $path_language = '');
print
$targetPath;
?>

Great from Google Merchant and Ubercart product nodes.

Facebook Share button in a view

Thanks. I used this piece of code to generate a FB share button that points to the intended node for each displayed node in the view. See here.

Use 100% Open Source, go Ubuntu. Dual boot easier than ever, no partitioning needed.

Hi, im using this code on my

Hi, im using this code on my custom field:php code in my view. but it doesn't get language of the node. what it gets its just node path alias. any advice on this one would be highly appreciated

Visuallemon

You can simplify your code

You can simplify your code considerably by using Drupal's API more:

<?php
print url('node/'. $data->nid, array('absolute' => TRUE));
?>

--
Jakob Persson - NodeOne

Tidy solution Jakob, but...

I came accross this answer and it does exactly what I wanted in a very succinct way, but for some reason it doesn't work - unless I use 'print' twice! - Any idea why this might be? If I write this in my page.tpl.php:

<?php
print url('node/'. $data->nid, array('absolute' => TRUE));
?>

I get no output, but if i write this:

<?php
print print url('node/'. $data->nid, array('absolute' => TRUE));
?>

Then I get the raw node ID?

Awesome

I was looking for the same thing. Thanks!

nobody click here