Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
[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
Online
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
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
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 />">» 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
Online
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 />">» 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
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
Online
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
Online
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
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
Online