Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-10-09 12:39:35

lee
Member
From: Normandy, France
Registered: 2004-06-17
Posts: 831

Get image id?

Anyone know a tag to return the image id used in the article image box in the write tab please?

best wishes
Lee

Offline

#2 2008-10-09 13:26:00

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Get image id?

Nope, but this should do the trick:

<txp:php>echo $GLOBALS['thisarticle']['article_image'];</txp:php>

Offline

#3 2008-10-09 13:37:45

lee
Member
From: Normandy, France
Registered: 2004-06-17
Posts: 831

Re: Get image id?

Thanks very much, could I trouble you to get it to return the txp assigned file name and not just the id:) Please

So for example:
33.jpg and not 33
28.gif and not 28

Offline

#4 2008-10-09 15:11:46

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Get image id?

I think this will return the image URL.

<txp:php>echo preg_replace('/^.*?src="([^"]+)".*$/', '$1', article_image(array()));</txp:php>

And if it does, this should return the filename:

<txp:php>echo preg_replace('/^.*?src="[^"]*?([^"\/]+)".*$/', '$1', article_image(array()));</txp:php>

Last edited by ruud (2008-10-09 18:07:11)

Offline

#5 2008-10-09 15:28:34

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: Get image id?

I thought upm_image could do both tasks: return the image ID and the file extension. But I’m looking at the help and it seems there isn’t any tag to return the file extension.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#6 2008-10-09 15:55:52

lee
Member
From: Normandy, France
Registered: 2004-06-17
Posts: 831

Re: Get image id?

Hi Rudd, the two snippets don’t return anything at all for me.
Hi Julián, thanks for the help.

Offline

#7 2008-10-09 17:29:08

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Get image id?

Edited earlier post, it contained an error.

Offline

#8 2008-10-09 17:49:29

lee
Member
From: Normandy, France
Registered: 2004-06-17
Posts: 831

Re: Get image id?

Hi Rudd, thanks for your time; both snippets give the article id.

Offline

#9 2008-10-09 18:06:47

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Get image id?

Third attempt (this happens when you write code without testing).

Offline

#10 2008-10-09 18:45:51

lee
Member
From: Normandy, France
Registered: 2004-06-17
Posts: 831

Re: Get image id?

Thank you Rudd, your help is much appreciated – working perfectly.

Offline

Board footer

Powered by FluxBB