Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2017-03-04 00:13:41

bici
Member
From: vancouver
Registered: 2004-02-24
Posts: 2,120
Website Mastodon

[SOLVED] Auto adding image to Excerpt field

To add an image to an article at the moment one can simply insert an image_id to the Article Image box on our write panel, and have it styled using css via a form file.
But how can we do this for the Excerpt field? In effect having an Article_excerpt filed one could fill in with image id(s).
I tried to accomplish this via a custom field but it failed, and it caused errors.
Perhaps this is doable at the moment but i could not find such an option.

How can this be accomplished? Also is this something that should be hardwired in core?


…. texted postive

Offline

#2 2017-03-04 06:29:12

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

Re: [SOLVED] Auto adding image to Excerpt field

Hi bici

What you are trying to achieve is very doable. The errors are because of the use of tags.

Could you please post what you have here?


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

Offline

#3 2017-03-04 13:04:34

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,925
Website GitHub

Re: [SOLVED] Auto adding image to Excerpt field

Hi bici,

If you’re just using the excerpt field as a second article_image field, it would, I think, be better to use a custom field.

The reason it’s probably not working with the excerpt field is that the excerpt is processed as textile. You need to set it under the “Advanced Options” dropdown to “leave text untouched” to use it as a basic field.

With a custom field you could do this:

<txp:images id='<txp:custom_field name="my-new-image-cf' />' form="my-image-gallery-form" />

using single quotes for the tag-as-tag-attribute case and a comma-separated list of image IDs in the custom field.


TXP Builders – finely-crafted code, design and txp

Offline

#4 2017-03-04 18:28:31

bici
Member
From: vancouver
Registered: 2004-02-24
Posts: 2,120
Website Mastodon

Re: [SOLVED] Auto adding image to Excerpt field

I was using these forms.

My default Article form:

<txp:if_excerpt>
           <a href="<txp:permlink />" title="<txp:title />">&#187; Read more</a>
    <txp:else />
    </txp:if_excerpt> 
 <div class="image-container">
 <txp:output_form form="article_image2" /> 
	</div>

And in the form article_image2:

 <txp:if_article_image>
   <txp:image id='<txp:custom_field name="article_image2">' />
</txp:if_article_image>

…. texted postive

Offline

#5 2017-03-04 18:55:04

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,925
Website GitHub

Re: [SOLVED] Auto adding image to Excerpt field

Hmm, not quite sure what you want to achieve, but I’ll take a guess.

At present your image-container shows whether or not there’s an excerpt, because it’s not inside the if_excerpt tag. Also, the image inside your image container that you specify in your custom field called article_image2 only shows if you also have an image in the regular article_image field. The reason why the custom_field tag isn’t working is the missing closing slash.

If what you want to achieve is a second article image that shows with the excerpt, you could do this:

<txp:if_excerpt>
    <a href="<txp:permlink />" title="<txp:title />">&#187; Read more</a>
    <txp:if_custom_field name="article_image2">
        <txp:image id='<txp:custom_field name="article_image2" />' wraptag="div" class="image-container" />
    </txp:if_custom_field>
</txp:if_excerpt>

Like I said, I’m guessing what you might want. You might even be able to do away with the if_custom_field tag-combo if txp:image doesn’t output anything when there’s no id. I can’t remember off hand.


TXP Builders – finely-crafted code, design and txp

Offline

#6 2017-03-04 20:26:16

bici
Member
From: vancouver
Registered: 2004-02-24
Posts: 2,120
Website Mastodon

Re: [SOLVED] Auto adding image to Excerpt field

Hi Jacop – thanks for the advice.

What i was trying to achieve was that if the excerpt field had textual content then output the text AND the image IF there was one.

( perhaps one may not even need any IF statements )


…. texted postive

Offline

#7 2017-03-05 05:26:41

bici
Member
From: vancouver
Registered: 2004-02-24
Posts: 2,120
Website Mastodon

Re: [SOLVED] Auto adding image to Excerpt field

Thanks jacop – now it is working!
one quibble… i have tried various combinations of placing the code but i cannot get the image to appear at the BEGINNING of the excerpt field … it only appears at the end of the field.

	<txp:body />
<!-- ===== if the article has an excerpt, display that -->
      <txp:if_excerpt>
      <div itemprop="description">
        <txp:excerpt />
<!-- ===== IF there is an image in excerpt display ===================== -->
<txp:if_custom_field name="article_image2">
        <txp:image id='<txp:custom_field name="article_image2" />' wraptag="div" class="image-container" />
    </txp:if_custom_field>
<!-- ===== / image in excerpt  ===================== -->
      </div>
    </txp:if_excerpt>  
<!-- ======= /end excerpt -->

…. texted postive

Offline

#8 2017-03-05 06:54:23

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

Re: [SOLVED] Auto adding image to Excerpt field

Did you try?

	<txp:body />
      <txp:if_excerpt>
		<txp:if_custom_field name="article_image2">
			<txp:image id='<txp:custom_field name="article_image2" />' wraptag="div" class="image-container" />
		</txp:if_custom_field>
		<div itemprop="description">
		<txp:excerpt />
		</div>
    </txp:if_excerpt>

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

Offline

#9 2017-03-05 07:44:09

bici
Member
From: vancouver
Registered: 2004-02-24
Posts: 2,120
Website Mastodon

Re: [SOLVED] Auto adding image to Excerpt field

thanks colak!! – i had tried something close to that. but without any luck…

Last edited by bici (2017-03-05 07:45:52)


…. texted postive

Offline

Board footer

Powered by FluxBB