Hello everyone! This is my first post on so I apologize if this is in the wrong spot.

I have a view set up to use fields as the style and am trying to make a custom onclick function for a div within the my theme. For the onclick to work I need to get the url for the node. Currently, Im using the node/[NID] to do this but was wondering if there as any function that would get the path_alias for me. For example, when theming a node, there is the variable $node_Url. It is important to me to keep the path_alias for the content, mainly for SEO, but also because node/145 is not too terribly user friendly. Any ideas?

<?php
// $Id: views-view-unformatted.tpl.php,v 1.6 2008/10/01 20:52:11 merlinofchaos Exp $
/**
 * @file views-view-unformatted.tpl.php
 * Default simple view template to display a list of rows.
 *
 * @ingroup views_templates
 */
?>
<div class="listitem blogitem" onclick="window.location.href = '/fistudio/node/<?php print $fields['nid']->content; ?>'">
        <div class="top"></div>
        <div class="center">
            <img class="shake" src="<?php print "/fistudio/".$directory ?>/images/blogpost.png"/>
            <p><strong><?php print $fields['title']->content; ?></strong>
            <?php print $fields['teaser']->content; ?></p>
        </div>
<div class="bottom"></div>
</div>

Thanks for you time!

Comments

quartarian’s picture

I just found a module that kind of does this for me: globalredirect. However, I would like to know if there is a variable that can achieve this without the redirect. Thanks again!

petebrady’s picture

You could try drupal_get_path_alias, using something along the lines of:

print drupal_get_path_alias('node/' . $fields['nid']->content, $path_language = '')

This should return the aliased path for your node.

Hope this helps.

quartarian’s picture

Thanks droopdog! That was exactly what I was looking for.