Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
A way to remove an image from an excerpt?
I have a small area on a home page that accesses the latest 6 stories from a section.
Page code:
<txp:article_custom form="myform" limit="6" section="my-section" />
Form:
<h3><txp:permlink><txp:title /></txp:permlink></h3>
<txp:excerpt />
What’s happening is that the users are entering massive images into the excerpt field (from Flickr in this case) that is breaking the home page design. Anyone know of a way to exclude images from the excerpt only on the home page?
Offline
#2 2007-12-28 13:32:11
- net-carver
- Archived Plugin Author
- Registered: 2006-03-08
- Posts: 1,648
Re: A way to remove an image from an excerpt?
Jonathan
Hello again. Can rss_auto_excerpt do something like stripping certain tags?
Edit: Hum, might not be exactly what you want though — I think it can pull from the excerpt if it’s present.
Last edited by net-carver (2007-12-28 13:33:43)
— Steve
Offline
#3 2007-12-28 14:05:46
- masa
- Member
- From: Asturias, Spain
- Registered: 2005-11-25
- Posts: 1,091
Re: A way to remove an image from an excerpt?
If you enclose you excerpts with for instance <div class="excerpt"> ... </div>
you can use a css rule to remove any images like so…
div.excerpt img { display: none }
Offline
Re: A way to remove an image from an excerpt?
Masa’s advice seems to be the simplest way – just add condition – if it “true” wrap required content with <span class="noimg">content</span>
.
span.noimg img {
display: none;
}
Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?
Offline
Re: A way to remove an image from an excerpt?
Thanks guys. Victor, what kind of condition are you referring to? if_conditional? Which one?
Offline
#6 2007-12-28 15:41:47
- masa
- Member
- From: Asturias, Spain
- Registered: 2005-11-25
- Posts: 1,091
Re: A way to remove an image from an excerpt?
I’m not sure what Victor had in mind, but the conditional statement is the css rule itself: if any <img>
is found within a container tagged with .excerpt it won’t be displayed.
If you wanted to only ensure that images won’t exceed a maximum dimension, you could also place the images in a separate container div of e.g. 160/160px and set that container’s overflow to “hidden” – that will crop any larger images. The downside is they will still be loaded.
Last edited by masa (2007-12-28 15:49:53)
Offline
#7 2007-12-28 16:09:39
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: A way to remove an image from an excerpt?
You can use etz_striptags with some conditionals to have it working only on the front page. Or rss_auto_excerpt (you can also make it use your own excerpt).
Last edited by els (2007-12-28 16:13:08)
Offline
Re: A way to remove an image from an excerpt?
As far as I can see, rss_auto_excerpt does not strip the images from the excerpt, if they exist. Neither does etz_striptags, because the image is within the excerpt tag, and I would like to check if there is an image before stripping it, but only on the front page.
This is the current form:
<h3><txp:permlink><txp:title /></txp:permlink></h3><txp:excerpt />
I think I will have to go down the CSS route to remove the img tag.
Offline
#9 2007-12-28 23:33:24
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: A way to remove an image from an excerpt?
<p><txp:etz_striptags><txp:excerpt /></txp:etz_striptags></p>
would strip the <img>
tags I think, but of course also all other html tags, and you may not want that.
Offline
Re: A way to remove an image from an excerpt?
Basically without plugins, cause it doesn’t exist yet – nor etz_striptags doesn’t allow to choose which tags to leave. Well, this removes all images. You can add there more allowed tags or remove them if you like:
<txp:php> echo strip_tags(excerpt(), '<p><a><em><ul><li><ol><strong><br><div><span><pre><code><abbr><del>');</txp:php>
Cheers!
Offline
Re: A way to remove an image from an excerpt?
Jukka, that seems a good way. I get errors though:
<txp:php> -> Warning: Missing argument 1 for excerpt(),
Code in the form is as follows:
<h3><txp:permlink><txp:title /></txp:permlink></h3>
<txp:php> echo strip_tags(excerpt(), '<img>');</txp:php>
If I use this:
<h3><txp:permlink><txp:title /></txp:permlink></h3>
<txp:php> echo strip_tags(excerpt(), '<img>'); <txp:excerpt /></txp:php>
The excerpt is not shown at all, and this error displays:
Parse error: syntax error, unexpected ‘<’ in /users/home/myname/web/public/textpattern/publish/taghandlers.php(2738) : eval()’d code on line
Offline
Re: A way to remove an image from an excerpt?
you can’t throw a txp tag within php like that.
Offline