Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2017-06-27 11:28:28

CodeWalker
Member
From: Hampshire, UK
Registered: 2010-01-08
Posts: 110
Website

Article Image URL

Hello… wow i haven’t posted in 2 years! but here goes…

I want to get the URL of the article image, which isn’t supported by the article image tag AFAIK. I seem to remember back in the mists of time that the built in article fields can be accessed with the custom field tag because they are essentially predefined custom fields…. am i right or have i had to much haribo this morning??

I was thinking something like this should work…but it doesnt….

<div class="article-image" style='background-image: url(<txp:image_url id='<txp:custom_field name="articleimage" />' />)'></div>

Any here would be great. Thanks.

Last edited by CodeWalker (2017-06-27 11:29:16)

Offline

#2 2017-06-27 12:02:41

CodeWalker
Member
From: Hampshire, UK
Registered: 2010-01-08
Posts: 110
Website

Re: Article Image URL

Figured it out. The images tag hits the article image first on its data hit list, so it can be done like this:

<div class="article-image" style='background-image: url("<txp:images limit="1"><txp:image_url /></txp:images>")'/></div>

Offline

#3 2017-06-27 12:44:28

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,293
Website GitHub

Re: Article Image URL

CodeWalker wrote #306100:

I was thinking something like this should work…but it doesnt….

So close! You were one character out in your original effort: the article image field is called article_image, with the underscore.

Welcome back, btw. Good to see you around.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#4 2017-06-27 14:00:03

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: Article Image URL

You can also use:

<div class="article-image" style='background-image: url("<txp:image_url id='<txp:custom_field name="article_image" />' />")'/></div> 

This can be found here on the forum but is somewhat undocumented outside of Display the first image from a list in the article image field.

Offline

#5 2017-06-27 14:28:14

CodeWalker
Member
From: Hampshire, UK
Registered: 2010-01-08
Posts: 110
Website

Re: Article Image URL

Bloke wrote #306102:

So close! You were one character out in your original effort: the article image field is called article_image, with the underscore.

Welcome back, btw. Good to see you around.

Your kidding me!! I tried that first and it spat in my face. Maybe I have i my single/double quote marks mangled.

Thanks Stef, Glad to see your still going. Hows that Amazon wish list looking these days? :)

- James

Last edited by CodeWalker (2017-06-27 14:28:31)

Offline

#6 2017-06-27 14:30:30

CodeWalker
Member
From: Hampshire, UK
Registered: 2010-01-08
Posts: 110
Website

Re: Article Image URL

michaelkpate wrote #306103:

You can also use:

<div class="article-image" style='background-image: url("<txp:image_url id='<txp:custom_field name="article_image" />' />")'/></div>...

This can be found here on the forum but is somewhat undocumented outside of Display the first image from a list in the article image field

Thanks for the nudge, that’s a little cleaner. I did poke around the forum but only found an impossibly old post that used raw PHP to directly grab the value…. hangs head that’s not the way I roll. :)

Last edited by CodeWalker (2017-06-27 14:30:58)

Offline

#7 2017-06-27 15:00:13

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: Article Image URL

CodeWalker wrote #306105:

I did poke around the forum but only found an impossibly old post that used raw PHP to directly grab the value…. hangs head that’s not the way I roll. :)

Me either.

Offline

Board footer

Powered by FluxBB