Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
tip: using HTML tag in article title and stripping it in <title> tag
Hi,
I was looking how to use an acronym (or any HTML tag) in the article title and also preventing from being outputted in the browser bar (the blue one that is above most browser) if the article title is being included in <code><title></title></code>.
Example: <ol> <li>Article title: <code>My top-ten <acronym title=“PHP: Hypertext Preprocessor”>PHP</acronym> mistakes</code></li> <li>Title tag: <code><title>My top-ten <acronym title=“PHP: Hypertext Preprocessor”>PHP</acronym></title></code><br /><span style=“color:red;”>This is not valid code!</span></li> <li>Browser title: <span style=“color: #fff; font-weight:bold; background: #009;”>My site :: My top-ten < acronym title=“PHP: Hypertext Preprocessor”>PHP< /acronym> mistakes</span><br /><span style=“color:red;”>This is not a nice title! (note I also added an space after < for the example to work in this forum)</span></li> </ol>
So, what can we do to avoid including HTML tags in <code><title></title></code> but to keep using them in article titles?
<ol>
<li>download <a href=“http://www.bluecamel.org/software/textpattern/sab_striphtml.txt”>sab_striphtml plug-in </a></li>
<li>download <a href=“http://rise.lewander.com/files/txpplugins/ob1-title-2.2.txt”>ob1_title</a> (this may be optional, but I havent tested with built int txp:page_title)</li>
<li>install the plug-ins and active them</li>
<li>in the page/form where you have your <code><title></code>, simple replace it with this:
<div style=“font-size:80%; overflow:auto;”><pre><title><txp:sab_striphtml><txp:ob1_title separator=” :: “ order=”%sitename,%article” /></txp:sab_striphtml></title></pre></div></li>
<li>voilà! any HTML tag in your HTML title will be stripped, and you will have a nice title</li>
</ol>
Please, give me feedback if you think that I have gone wrong somewhere or if you think this can be done without plug-ins.
Thanks.
Offline
#2 2005-10-27 20:15:51
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: tip: using HTML tag in article title and stripping it in <title> tag
Nice one. Thanks for sharing. :)
Offline
Re: tip: using HTML tag in article title and stripping it in <title> tag
It is also nice that you can include, in the separator attribute (for ob1_title), html entities like &#187; (») and this wont be stripped.
:D
Offline
Re: tip: using HTML tag in article title and stripping it in <title> tag
New found on this:
you can also use HTML tags in section titles, and those tags will be stripped when the section title appears in the browser title bar.
Now, you can use <code><acronym></code> tags, or even more than one <code><span></code> tags in your section titles (to achieve psychodelic section names with multiple colors and fonts and whatever) and still keep your browser titles nice and valid. :D
Edit: and in categories too!
Last edited by maniqui (2005-10-27 22:34:59)
Offline
#5 2005-10-27 22:44:17
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: tip: using HTML tag in article title and stripping it in <title> tag
The plugin would work for any text you wrap it around, whether from a tag, or entered manually. :) Nice huh?
Offline
Re: tip: using HTML tag in article title and stripping it in <title> tag
Great! Now I can have the descriptive page titles at the top that the search engines like and still have short titles for each articles! I just wrap the extra description in italics (i) tags, put i {display: none; } in the css and hey presto! Nice one, Maniqui :-)
Offline
Re: tip: using HTML tag in article title and stripping it in <title> tag
It’ seems that now (4.0.2) you cant use HTML elements in article titles. :(
igner pointed that the change is related to this discussion
Personally, I think that this change in 4.0.2 is a step backward in the flexibility of TXP.
What if I want/need to use strong, em, acronym, abbr in my article titles?
Wasnt this one a valid solution for removing HTML elements in <code><title></code>?
Offline
Re: tip: using HTML tag in article title and stripping it in <title> tag
I would be interested in a workaround for this too.
I currently use Category :<code><txp:c /></code> for the title of a category intro article.
It doesn’t parse now :(
Thanks,
matthew
- I am Squared Eye and I
am launchinghave launched Pattern Tap
Offline
#9 2005-11-04 07:38:31
- boblet
- Member
- Registered: 2005-08-08
- Posts: 53
Re: tip: using HTML tag in article title and stripping it in <title> tag
does anyone know where this happens in the code, or even better what to change it to, to revert to the 4.01 behaviour? Call me twisted, but I get a kick outta encoding my own titles (that and it gives me more options ;-) Any other workaround would be great too
peace – boblet
PS maybe we could have a user-editible ‘ignored list’ preference specifying tags we’d like to allow in comments and titles – I wonder how feasible this would be to implement as a plugin (?)
Update: Here’s the relevant changeset to publish/taghandlers.php
should you want to revert to the old behaviour enough to hack your source. Hopefully this will be be addressed at some stage by a toggle preference, a user-editible ‘ignored list’ preference, or even Textile being educated somehow to strip relevant html from <title>
but leave it when the title is called in a <h#>
. Or by a plugin. Maybe…
;-)
Last edited by boblet (2005-11-04 09:53:09)
Offline
Re: tip: using HTML tag in article title and stripping it in <title> tag
You can affect these changes with forms if you prefer? You would need a standard number of forms like
article – blue
article – red
article – big
etc.
Then you could format the title inside the form?
<code>
<h3 class=“red”><txp:permlink><txp:title /></txp:permlink></h3>
</code>
<code>
h3.red {
color: red;
}
</code>
etc.
I guess you are probably looking at this saying, yeah, duh! dude, I already know how to do that, but I want to do it the way I was doing it. That’s what I would be saying about now. Anyhow, I put it there in case anybody, wants to try something different.
Matthew
- I am Squared Eye and I
am launchinghave launched Pattern Tap
Offline
#11 2005-11-17 23:43:28
- Vitruvius
- Plugin Author
- Registered: 2004-09-21
- Posts: 125
Re: tip: using HTML tag in article title and stripping it in <title> tag
Just adding my voice to this thread re: encoding your own titles. I have an example where I want to display an article title with a ® in superscript. In 4.0.1 I just entered the title as:
<code>My title<sup>®</sup></code>
which worked fine to produce:
My title^®^
But now, obviously I have to live with:
My title®
which doesn’t look quite as nice :)
I agree that valid HTML should be produced out of the box.
Why not enable a subset of textile for article titles?
SH
Offline