Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
[archived] sab_substr
Notice: This thread is archived, this plugin is no longer available. rvm_substr offers this functionality
**********************************************************
http://www.bluecamel.org/software/textpattern/sab_substr.txt
<code><txp:sab_substr limit=“10” trail=”…”>content to take a substring of like <txp:title /></txp:sab_substr></code>
This is a simple plugin to cut a string of text at a specified character limit, then add a string to the end, like ellipses.
It will take an article title and trim it down to a specified character limit then add an ellipses. Possibly used for article navigation (prev/next) or an article list where you want to keep the titles short.
Example:
<code><txp:sab_substr limit=“10” trail=”…”>long string of text</txp:sab_substr></code>
will output
“long strin…”
<h3>Reference</h3>
<ul>
<li><strong>trail=</strong> – The string you want appended to the result. It will NOT be appended UNLESS the content was trimmed. Defaults to <strong>…</strong>.</li>
<li><strong>limit=</strong> – The length of the string you want returned, minus the length of <strong>trail</strong>. Defaults to <strong>10</strong>.</li>
</ul>
Last edited by supa (2005-05-20 12:55:22)
Offline
Re: [archived] sab_substr
Has anyone had success using this? I applied the tag but the title still remains on two lines. I modified it to only show 5 characeters and it remained the same.
Thanks in advance
Offline
Re: [archived] sab_substr
I used this a little a while ago (rc1&rc2), but not recently. I wonder if the new humane titles are interfering? What version of txp are you on?
Offline
Re: [archived] sab_substr
the one on the front page. I;m trying to use it in a form, but no joy
Offline
Re: [archived] sab_substr
Thanks sekhu for PMing me!
I wasn’t aware of any problem with this plugin. It uses standard PHP and only relies on one TXP function (parse()). I’ll update my copy of TXP and see if I can figure out what’s wrong!
-sab
Offline
Re: [archived] sab_substr
wow thanks. so email does have a purpose!
Offline
Re: [archived] sab_substr
Hm, well, I’m afraid I don’t have good news for you :( It works fine for me!
Can you describe the context that you’re using it in? (form, in any ef/else blocks, when the form gets output, etc)?
-sab
Offline
Re: [archived] sab_substr
damn I don’t seem to be having much luck :(
Ok the context: http://www.sekhu.net/txpattern/
The form in which I’m using it:
<pre><h2 class=“music”>
<sab_substr limit=“10” trail=”…”>
<txp:category1 link=“y” />
</sub_str>
</h2><br />
<h3 class=“music”><txp:permlink><txp:title /></txp:permlink></h3><br />
<p>
<txp:beginning length=“100” /><div class=“mmore”><txp:permlink>continue reading</txp:permlink></div>
</p></pre>
So the box with “music” as the title would have that two line title link truncated to 10 characters. I am using this within article_custom – is that going to cause an issue?
Cheers
Offline
Re: [archived] sab_substr
Okay, well hopefully you didn’t copy and paste that and you just retyped it wrong :P
1) The tag is <code><txp:sab_substr limit=“10” trail=”…”></code>, not <code><sab_substr limit=“10” trail=”…”></code>
2) The tag is <code></txp:sab_substr></code>, not <code></sub_str></code>
Also, remember, that when link=“y” there is some text prepended to the category to make the link (“<code><a href=“blah”>category</a></code>”). That’s factored into the “limit” attribute of sab_substr. In that case, I don’t think sab_substr will do what you need. At least not with the <code><txp:category1 link=“y” /></code> tag.
-sab
Last edited by supa (2005-05-20 02:30:30)
Offline
Re: [archived] sab_substr
> supa wrote:
> Okay, well hopefully you didn’t copy and paste that and you just retyped it wrong :P
1) The tag is <code><txp:sab_substr limit=“10” trail=”…”></code>, not <code><sab_substr limit=“10” trail=”…”></code>
2) The tag is <code></txp:sab_substr></code>, not <code></sub_str></code>
Hmmm – I was going by your example at the top of the page :)
<pre>Example:
<sab_substr limit=“10” trail=”…”>long string of text</sab_substr>
will output</pre>
so this won’t work with links?
Cheers anyway
Offline
Re: [archived] sab_substr
Wow, How’s that for a pie in the face?
It won’t work with links unless the link is around the <code><txp:sab_substr /></code> plugin, like:
<code>
<a href=“blah.html”><txp:sab_substr limit=“15”>content goes here</txp:sab_substr></a>
</code>
Sorry :(
-sab
Offline
Re: [archived] sab_substr
hmm i’m a muppet I don’t know why I surrounded the tag with the cat isnide – it’s not the cat i;m truncating. i want to trancate the article title…
so, would this work?
<pre>
<h3 class=“music”>
<txp:permlink>
<txp:sab_substr limit=“10” trail=”…”>
<txp:title />
</txp:sab_substr>
</txp:permlink>
</h3></pre>
EDIT: That didn’t work either – is there no other way to truncate titles? It really would be something I could use and would save me having to limit users to how long titles are.
Last edited by sekhu (2005-05-20 16:42:11)
Offline