Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#277 2025-02-24 18:10:24
- msome
- Member
- Registered: 2015-09-16
- Posts: 40
Re: [plugin] [ORPHAN] rss_auto_excerpt
Thanks for the answer!
The html page is generated in this format, already with the help of my script, at this stage everything is ok, the images are placed where they should be, ok.
The images are put in “textarea” manually via the button on the panel (arrow in the screenshot).
You need to delete all paragraphs/divs except the first two and the last one.
admin panel
website
Of course, this can be done via CSS, but I would not want to. So that initially unnecessary content is not loaded into “except”.
<txp::img_gallery /> does not show the presence of images in the article added in this way.
Last edited by msome (2025-02-24 18:34:50)
Offline
#278 2025-02-24 21:31:05
Re: [plugin] [ORPHAN] rss_auto_excerpt
Okay, got you. You’re using something else (tinyMCE?) to generate direct HTML for your body so shortcodes won’t be processed. I guess you could add another option to rss_auto_excerpt but it’s a very specific case.
How about this for an alternative suggestion? It’s similar to the previous idea but uses etc_query to retrieve the div node with the images in it and tag it on the end of the rss_auto_excerpt. You’ll first need to install etc_query.
Then try a setup like this in your article_list code:
<txp:rss_auto_excerpt overrideexcerpt="1" paragraphs="2" showlinkwithexcerpt="0" />
<txp:etc_query data='<txp:body />' query="//div[@class='img_inner']" />
<txp:permlink>Keep reading …</txp:permlink>
This is the rss_auto_excerpt tag with however many paragraphs you want. I added showlinkwithexcerpt="0"
to suppress the “Keep reading …” link after the paragraphs.
Then etc_query retrieves your div with your specific class from within the article body using XPath syntax.
The “Keep reading…” is then added back in at the end using txp:permlink.
I tried this out with a manually input html only body text and it worked nicely:
and
TXP Builders – finely-crafted code, design and txp
Offline
#279 2025-02-25 13:06:00
- msome
- Member
- Registered: 2015-09-16
- Posts: 40
Re: [plugin] [ORPHAN] rss_auto_excerpt
Thanks for the help jakob!
Yes, it works in manual mode.
But I have it connected in the footer <script src=“script.js” defer></script>
This script creates a div.img__inner block and all the images of the article are moved there.
But I can’t make it work like that, maybe the script starts working before the page is rendered…
Offline
#280 2025-02-25 13:46:07
Re: [plugin] [ORPHAN] rss_auto_excerpt
Both rss_auto_excerpt and etc_query (in the way shown above) act on the content of the Textpattern’s article body as it comes out of the database (e.g. the body_html
field in the database) and then renders that to the page. They have no knowledge of what might subsequently be re-rendered with javascript after the page loads, so I don’t think either plugin can help you there.
Can you perhaps solve it differently without using javascript? You said that the script collects all the article images and renders them inside a div.img__inner
. Where are your article images inserted?
- If they are in the article_image field, you could use the regular txp:images tag to render the images from there.
- If they are inserted individually at different places in your article body using TinyMCE, maybe try the etc_query method above but adjust the XPath search query to grab all the images inside the article. Then wrap them in your page template or form with the
div
you want.
For example:
<!-- rewrap all images from within the 'img__inner' class -->
<txp:etc_query data='<txp:body />' query="//div[@class='img__inner']/img" wraptag="div" class="img__items" />
<!-- rewrap all images from the article body -->
<txp:etc_query data='<txp:body />' query="//img" wraptag="div" class="img__items" />
will retrieve just the img tags and rewrap them in a div with class img__items.
Maybe you don’t need your javascript at all after that.
TXP Builders – finely-crafted code, design and txp
Offline
#281 2025-02-25 15:44:00
- msome
- Member
- Registered: 2015-09-16
- Posts: 40
Re: [plugin] [ORPHAN] rss_auto_excerpt
Now the images are transferred to div.item__images, which is now created by the etc_query plugin
But for some reason the images are duplicated…
default form:
<txp:if_article_list>
<div class="main__content-item item">
<p class="item-title">
<txp:permlink class="item__title-link"><txp:title /></txp:permlink>
</p>
<txp:rss_auto_excerpt overrideexcerpt="1" paragraphs="2" showlinkwithexcerpt="0" />
<txp:etc_query data='<txp:body />' query="//img" wraptag="div" class="item__images" />
</div>
<txp:else />
<div class="main__content-item item">
<p class="item-title">
<txp:permlink class="item__title-link"><txp:title /></txp:permlink>
</p>
<txp:body />
<txp:excerpt />
<txp:etc_query data='<txp:body />' query="//img" wraptag="div" class="item__images" />
</div>
</txp:if_article_list>
Last edited by msome (2025-02-25 15:44:41)
Offline
#282 2025-02-25 17:14:47
Re: [plugin] [ORPHAN] rss_auto_excerpt
Looks good. If the duplication is happening in the individual article view, then I guess it is because you have <txp:body />
and <txp:etc_query data='txp:body />' …
. See what your source code looks like.
Otherwise I’m not sure. I presume you don’t have the same image twice in the article? My Xpath knowledge is rudimentary, so maybe you can tweak the query. There are tutorials online, and the web inspector can also help in telling you the Xpath for a DOM node.
TXP Builders – finely-crafted code, design and txp
Offline
#283 2025-02-25 21:49:09
- msome
- Member
- Registered: 2015-09-16
- Posts: 40
Re: [plugin] [ORPHAN] rss_auto_excerpt
<txp:rss_auto_excerpt overrideexcerpt="1" paragraphs="2" showlinkwithexcerpt="0" />
<txp:etc_query data='<txp:body />' query="//img" wraptag="div" class="item__images" />
Yes, let’s say there is an image in the article in paragraph 1 or 2.
a) It is displayed here.
<txp:rss_auto_excerpt overrideexcerpt="1" paragraphs="2" showlinkwithexcerpt="0" />
b) And it is displayed here.
<txp:etc_query data='<txp:body />' query="//img" wraptag="div" class="item__images" />
If you remove a) there will be no article text.
If you remove b) a div with all the images from the article (body) will not be created
Offline
#284 2025-02-25 22:00:52
Re: [plugin] [ORPHAN] rss_auto_excerpt
msome wrote #339144:
<txp:rss_auto_excerpt overrideexcerpt="1" paragraphs="2" showlinkwithexcerpt="0" />...
Yes, let’s say there is an image in the article in paragraph 1 or 2.
Hmm. Try adding escape="img"
to the rss_auto_excerpt tag:
<txp:rss_auto_excerpt overrideexcerpt="1" paragraphs="2" showlinkwithexcerpt="0" escape="img" />
The idea here is to strip image tags out of the first instance of the body. See the docs – using img
is the escape="some-tag"
option in that list.
TXP Builders – finely-crafted code, design and txp
Offline
#285 2025-02-26 17:29:17
- msome
- Member
- Registered: 2015-09-16
- Posts: 40
Re: [plugin] [ORPHAN] rss_auto_excerpt
Yes, it worked! Hooray, well done! Thanks!
Offline
#286 2025-02-26 20:47:18
Re: [plugin] [ORPHAN] rss_auto_excerpt
Glad it worked 👍
TXP Builders – finely-crafted code, design and txp
Offline