Im theming a content type with its tpl file and im using this to theme the teaser view;

?>
<?php if (!$page) { ?>

How should I link the Node's title to its full page?

If I use this;

<?php print $node->path ?>

It prints a relative path so I need to hard code the beginning of the site url;

<a href="http://MYSITENAME/<?php print $node->path ?>"><?php print check_plain($node->title) ?></a>

This isn't ideal as my site is currently on a local environment and the url will change when it goes live. Normally Pathlogic can fix this for me, but Pathlogic only works in node content not in a template file.

Should I be printing different php or is there a way of calling this 'http://MYSITENAME/' dynamically?

Ive searched but im surprised I cant find any advice on this, i would have thought it would be a common requirement.
Thanks

Comments

jerseycheese’s picture

Use the l() function for smarter linking. Drupal will convert it to the custom path you've given the page if using pathauto module.

<?php print l($node->title, '/node/' . $node->nid); ?>

Otherwise if you really want to use $node->path, you can hardcode your link like this, it'll refers to the site's root if you put a forward slash before the path:

<a href="/<?php print $node->path ?>"><?php print check_plain($node->title) ?></a>
jdln’s picture

The first code links to something like node/99. If you remove the first slash from '/node' it links to the path that ive set with path auto;

<?php print l($node->title, 'node/' . $node->nid); ?>

They both work but im wondering if the path auto url is better for seo.
Thanks

jerseycheese’s picture

Pathauto url is definitely better for SEO.

hashmat0811’s picture

Use drupal_get_path_alias code to print the get desired URL alias od a node

<?php print l($node->title, drupal_get_path_alias("node/$node->nid")); ? 

or we can use some string 'Read More' instead of the $node->tilte

Regards.

faicalo’s picture

Assuming your content type is called "blog", then node-blog.tpl.php will be used whenever a blog post needs to be displayed. The $teaser variable will be set to TRUE in node-blog.tpl.php if Drupal is wanting the teaser display, and the $page variable will be set to TRUE if the node is being shown in full page view (they will both be FALSE if the full node is being shown in a list of nodes). So you need to set up your node-blog.tpl.php to check for what type of display is being requested and return the HTML appropriate to the given type. The general setup of your node-blog.tpl.php should be along these lines