Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2008-04-21 16:28:03
- Sandwich
- Member
- Registered: 2005-02-14
- Posts: 37
Output only the URL of article image?
How can I output nothing but the URL of an article image? Just what’s in the IMG tag’s src=”“ attribute, nothing more. I’m not averse to using plugins, hacks, or even Deep Magic from Before the Beginning of Time…
Offline
Re: Output only the URL of article image?
Not sure if this falls under hacks or Deep Magic, but…
If you have filled in a complete URL in your article image field, it’s easy:
<txp:php>
global $thisarticle;
echo $thisarticle['article_image'];
</txp:php>
If you’re using just the article ID… well, not that complicated either:
<txp:php>
global $thisarticle, $img_dir;
$image = intval($thisarticle['article_image']);
$ext = safe_field('ext', 'txp_image', 'id = '.$image);
echo hu.$img_dir.'/'.$image.$ext;
</txp:php>
Although if all your images are in the same format and have the same extension, say ‘.jpg’, you could simplify that to:
<txp:php>
global $thisarticle, $img_dir;
$image = intval($thisarticle['article_image']);
echo hu.$img_dir.'/'.$image.'.jpg';
</txp:php>
PS. none of the above solutions is tested.
Offline
#3 2008-04-21 18:01:00
- Sandwich
- Member
- Registered: 2005-02-14
- Posts: 37
Re: Output only the URL of article image?
Wow, comprehensive answer. :) Thanks! Since I posted this, though, I figured out a solution, using the upm_image plugin (<txp:upm_article_image><txp:upm_img_full_url /></txp:upm_article_image>). But it’s certainly good to see that the solution wasn’t some simple thing staring me right in the face! ;)
Offline
Pages: 1