Having a problem with relative path to /wp-content/uploads/ (( I think ))
-
Howdy, can anyone see a problem with this code?
I suspect I’m doing the relative url to the /wp-content/uploads/ wrong but can’t figure it out.
<div class="image_wrap"> <?php $posttags = get_the_tags(); // Get articles tags $home = get_bloginfo('url'); // Get homepage URL // Check if tag-slug.jpg exists and display it. if ($posttags) { foreach($posttags as $tag) { $image = "/wp-content/uploads/$tag->slug.jpg"; if (file_exists("wp-content/uploads/$tag->slug.jpg")) { echo '<a href="' . $home . '/' . $tag->slug . '" /><img title="' . $tag->name . '" alt="' . $tag->name . '" src="' . $image . '" /></a>'; // If no image found, output something else. } else { ?> <img src="<?php bloginfo('template_directory'); ?>/img/default-author.jpg" title=" image missing " /> <?php } } } ?> </div><!-- #image_wrap -->
The output IS showing the default-author.jpg as it should if it can’t find an image in the folder with the same name as the tag slug … that’s why I suspect my relative url structure is wrong here … because the ‘uploads’ folder does have those images in it.
For example:
If the tag slug is ‘frank-jackson’ it should find and display the ‘frank-jackson.jpg’ image in the ‘wp-content/uploads’ folder, wrapped in a link pointing to that tag page.
Note: I’m using a ‘no tag slugs in url’ plugin, so that’s why I don’t have /tags/ in that output/echo url.
Earlier, before I added the ‘else show default image part’ it WAS outputting a <img> wrapped in a proper link to the tag page as it should, but just wasn’t showing the image.
I think I’m just not sending it on the proper path the to wp-content/uploads directory because all the other parts seems to be working.
Thanks
[+
]
- The topic ‘Having a problem with relative path to /wp-content/uploads/ (( I think ))’ is closed to new replies.