Hi there Drupal droogs,
I've been using the following code in the node tpl file to create a read more link in the node teaser:
<?php print "<a href='/" . $node->links["node_read_more"]["href"] . "' class='readmore' title='" . $node->links["node_read_more"]["attributes"]["title"] . "..' >" . '<img src="' . base_path() . path_to_theme() . '/images/read-more.gif" width="120" height="40" alt="" />' . "</a>"; ?>
Now $node->links["node_read_more"]["href"] works fine at creating the right URL until I put the site into a sub directory, and then instead of the links being /themes/?q=node/62 they are /node/62... which is wrong
Does anybody have any ideas what I can do to sort this problem out?
Regards,
Andy
Andy Walpole wrote:
I've been using the following code in the node tpl file to create a read more link in the node teaser:
<?php print "<a href='/" . $node->links["node_read_more"]["href"] . "' class='readmore' title='" . $node->links["node_read_more"]["attributes"]["title"] . "..' >" . '<img src="' . base_path() . path_to_theme() . '/images/read-more.gif" width="120" height="40" alt="" />' . "</a>"; ?>
Now $node->links["node_read_more"]["href"] works fine at creating the right URL until I put the site into a sub directory, and then instead of the links being /themes/?q=node/62 they are /node/62... which is wrong
Does anybody have any ideas what I can do to sort this problem out?
I would look into using the l() [1] function for this. It would look something like this:
<?php l('<img src="' . base_path() . path_to_theme() . '/images/read-more.gif" width="120" height="40" alt="" />', 'node/'. $node->nid, array( 'attributes' => array( 'title' => t($node->links["node_read_more"]["attributes"]["title"]), 'class' => 'readmore', ), 'html' => TRUE, ), ?>
The indentation is all off because this is email, but you can read up on l() and look at what I'm doing with this example and probably get it right. This should assure that you can move the site around safely.
Hope that helps, ~~Nat
[1] http://api.drupal.org/api/function/l/6
Using a function like l() to make your links is certainly better in general, but the actual reason why your code isn't working is this: print "<a href='/" . When you move your site to a subfolder of the root directory, you're changing the base URL of the site from '/' to '/[subfolder]'. I think your problem will be solved if you instead use something like this: print "<a href='" . $base_path . $node->... (see http://api.drupal.org/api/global/base_path/6 for details)
Hope that helps.
Andy Walpole wrote:
Hi there Drupal droogs,
I've been using the following code in the node tpl file to create a read more link in the node teaser:
<?php print "<a href='/" . $node->links["node_read_more"]["href"] . "' class='readmore' title='" . $node->links["node_read_more"]["attributes"]["title"] . "..' >" . '<img src="' . base_path() . path_to_theme() . '/images/read-more.gif" width="120" height="40" alt="" />' . "</a>"; ?>
Now $node->links["node_read_more"]["href"] works fine at creating the right URL until I put the site into a sub directory, and then instead of the links being /themes/?q=node/62 they are /node/62... which is wrong
Does anybody have any ideas what I can do to sort this problem out?
Regards,
Andy