Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-04-23 13:07:46

progre55
Member
Registered: 2006-05-02
Posts: 668

Article Image: Alt & Title

Group:

I have a project where I need to assign an image to an article. Easy. The next part is where I have run into difficulty. I need the outputed code to use (2) ARTICLE custom fields to fill in the IMAGE title and alt fields.

I have tried my standard when I have pulled info from custom fields, but this does not appear to work for me in this case. I know that I could assign the “alt” and probably the “title” info under the image tab but this will not work for what I need to accomplish.

Any assistance would be appreciated.

progre55

Last edited by progre55 (2012-04-23 13:08:12)

Offline

#2 2012-04-23 13:30:23

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,001
Website GitHub

Re: Article Image: Alt & Title

Hi Randy, I’d suggest constructing the img tag semi-manually:

<txp:images id='<txp:custom_field name="article_image" />'>
<img src="<txp:image_url />" 
     height="<txp:image_info type="h" />"
     width="<txp:image_info type="w" />"
     alt="<txp:custom_field name="custom-field-one" />"
     title="<txp:custom_field name="custom-field-two" />" 
     />
</txp:images>

Last edited by jakob (2012-04-23 13:31:01)


TXP Builders – finely-crafted code, design and txp

Online

#3 2012-04-23 13:36:50

progre55
Member
Registered: 2006-05-02
Posts: 668

Re: Article Image: Alt & Title

jakob —

THANK YOU. This is heading me in the right direction and working so far —

Can you tell me how I may modify the above so that the “alt” and title” are not custom fields — but the ARTICLES title and excerpt —-

progre55

Offline

#4 2012-04-23 13:39:12

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,258
Website GitHub Mastodon Twitter

Re: Article Image: Alt & Title

I think that this would work

<txp:article_custom id='<txp:article_id />'>
<txp:images id='<txp:custom_field name="article_image" />'>
<img src="<txp:image_url />" 
     height="<txp:image_info type="h" />"
     width="<txp:image_info type="w" />"
     alt="<txp:excerpt />"
     title="<txp:title />" 
     />
</txp:images>
</txp:article_custom>

>Edited to wrap it in article custom so as to avoid the comment forms. take out the article_id and give it a limit if you want it to work in article_list

Last edited by colak (2012-04-23 13:43:33)


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#5 2012-04-23 13:46:50

progre55
Member
Registered: 2006-05-02
Posts: 668

Re: Article Image: Alt & Title

Thank you both. This definitely is where I need to be. Now it is some tweaking on my side to get everything set — but THANK YOU — again for the assistance —-

progre55

Offline

#6 2012-04-23 14:16:11

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,258
Website GitHub Mastodon Twitter

Re: Article Image: Alt & Title

I would use a plugin to stop any html happening in the excerpt field.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#7 2012-04-23 14:29:04

progre55
Member
Registered: 2006-05-02
Posts: 668

Re: Article Image: Alt & Title

colak:

Thanks for the advise and guidance. Much appreciated.

progre55

Offline

Board footer

Powered by FluxBB