开发者

Trivial front page URL in PHP question

I would like to show an image link (image is on my s开发者_Go百科erver) in the PHP block (Drupal 7). When I put

<?php
print '<p align="right"><a href="http://something.com"> <img src="'.$front_page.'/misc/something.png">Caption</a>';
?>

it works but picture is only visible on the front page, on others it shows broken link. Why? What should I add then to this concatenation to make it work and to avoid putting hardcoded page URL?

Any help would be appreciated.


In Drupal, you should be able to run it through url() to get a proper path, i.e. url('misc/something.png').


The best way to troubleshoot this issue is to look at the src attribute of the page when the image is visible, and compare it to the src attribute of the page when the image is not visible. The differences may be revealing.

If this does not solve the problem, check to see if one of your pages uses a <base> tag. This may be adding data to your image path in an unexpected manner.


@Gawi, When possible, you should really use Drupal's API to add links, images, etc instead of hard-coding them. For example:

<?php
  GLOBAL $base_url;
  $variables = array('path' => $base_url . '/misc/blog.png', 'alt' => 'something.com logo');

  print '<p align="right">' . l(theme('image', $variables) . 'Caption', $base_url, array('html' => TRUE)). '</p>';
?>

Documentation on the variables/functions used:

  • $base_url
  • l()
  • theme_image()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜