Hopefuly I'm filing this correctly as I'm not sure if this is more a "Drupal themeing" issue or a Zen (my theme's base) issue.

I'm trying to place an "tag" icon before my taxonomy links in a node. I've found the appropriate place to insert my image in node.tpl.php, but the problem is I can't get it to consistently find the correct path to my icon. Currently, my code on node.tpl.php reads

<?php if ($terms): 
			$tagimg = drupal_get_path('theme', 'thecloudonline') . '/images/tag.png';      
      ?>
        <div class="terms terms-inline"><img src="<?php print $tagimg ?>" alt="Tag" /><?php print t('Tagged in ') . $terms; ?></div>
      <?php endif; ?>
    </div>

So what I'm trying to do is get the path to that tag.png file. For me, that yields sites/all/themes/thecloudonline/images/tag.png, which only works if the page address is one layer deep. If it more than one, it can't find it, as it's falling one level in the folder heiarchy short (for example, it works on my page "site.com/articles", but not on "site.com/article/sample-article-0". Is there a way to get the full (relative?) path so that it is always fully accurate?

Comments

cog.rusty’s picture

Try base_path() . drupal_get_path('theme', 'thecloudonline')

This (a) adds at least a front slash which makes the path absolute (a relative path can never work with clean URLs) and (b) also adds the base URL path of the site (e.g. /drupal), if there is one.

nevets’s picture

You can also get rid of the path issue in cases like this using css. Remove the image tag from the output and add this css to you theme (probably style.css)

.terms {
  background: url(images/tag.png) no-repeat;
  padding-left: 20px;
}

The padding should equal the width of the image plus any padding/space you want.

peacho’s picture

Sorry for the long, delay: I just got around to implementing this fix. I don't know why I didn't just go for that technique first, I know I've done similar in the past!