- Posts: 58
COMMUNITY FORUM
Ability to Display Tags and Styles in Intro Text
- Timothy Michel
-
Topic Author
- Offline
- Senior Member
Take a look here: www.jsandbox.org/evidence/videos/videos-by-others/content/161-confronting-nist.html
I want <a href="">, <p>, <strong>, <b>, <i> and the styles applied to these tags to survive the tags and styles stripping process.
Please Log in or Create an account to join the conversation.
- Lefteris
-
- Offline
- Platinum Member
- Posts: 8743
Please Log in or Create an account to join the conversation.
- Timothy Michel
-
Topic Author
- Offline
- Senior Member
- Posts: 58
Please Log in or Create an account to join the conversation.
- Lefteris
-
- Offline
- Platinum Member
- Posts: 8743
<?php echo JHTML::_('string.truncate', ($this->item->introtext),20); ?>
Please Log in or Create an account to join the conversation.
- Timothy Michel
-
Topic Author
- Offline
- Senior Member
- Posts: 58
You mean replace:
<?php if($this->item->params->get('catItemIntroText')): ?>
<!-- Item introtext -->
<div class="catItemIntroText">
<?php echo $this->item->introtext; ?>
</div>
<?php endif; ?>
with:
<?php if($this->item->params->get('catItemIntroText')): ?>
<!-- Item introtext -->
<div class="catItemIntroText">
<?php echo JHTML::_('string.truncate', ($this->item->introtext),132); ?>
</div>
<?php endif; ?>
Remove the value from "Introtext word limit" in "Item view options in category listings" leave "Introtext" as "show" and remove the read-more link from the item.
Please Log in or Create an account to join the conversation.
- Timothy Michel
-
Topic Author
- Offline
- Senior Member
- Posts: 58
<?php echo JHTML::_('string.truncate', ($this->item->introtext),1024); ?>
But the Joomla routine counts tag characters as well as content characters so that an item with a lot anchors will have less characters displayed than an item with few anchors.
The way the count should be done is that when a '<' character is encountered, the count isn't incremented until after a '>' character is encountered. that way tags won't be counted. The problem arises when the counter routine encounters text like '20 < 100'. I suppose the way around that is to have specific character sequences look-ups like '<p' and '<a' and '<h1' and '<h2' etc. if these sequences are encountered, then the counter value for the loop would have to be increased by the amount of the characters contained in those sequences.
I decided to set 'Introtext HTML cleanup (tag strip)' to 'No" and judiciously place the read more link so that it displays the correct amount of characters. I will have to make the writers to carefully adjust the read-more link to get the right results. This produces the most pleasing results even if it consumes a bit of time to correctly position the read-more link.
Please Log in or Create an account to join the conversation.
- Timothy Michel
-
Topic Author
- Offline
- Senior Member
- Posts: 58
In "Item view options in category listings" I set "Introtext" to "Show" and "Introtext word limit" to 150. In "Item view options" I set "Introtext" to "Hide" and "Fulltext" to "Show." This has K2 stripping the Intro Text of all tags. The problem I had with this is that K2 is counting words and not characters which means that the word count is the same for each Item Intro, but the character count isn't. To remedy this I replaced <?php echo $this->item->introtext); ?> with <?php echo JHTML::_('string.truncate', ($this->item->introtext),640); ?> in category_item.php which counts out 640 characters from the stripped intro text and display that through the echo command. 640 characters is less than 150 words so an ellipsis get appended at the end and everything looks good. Now I have to have dedicating intro text at the beginning of the articles, and I still have to insert a read-more link after the intro text, but I get category views for items that follow a uniform grid pattern, though all tags are stripped, but I get the full text view of the items with all formatting applied including the Intro text if I duplicate that above and below the read-more link.
You can see the results here
By adding a dozen @media queries in K2.css I was able to get the item intro containers grid to remain uniform regardless of viewport resolution..
Please Log in or Create an account to join the conversation.
- Lefteris
-
- Offline
- Platinum Member
- Posts: 8743
Please Log in or Create an account to join the conversation.
- Timothy Michel
-
Topic Author
- Offline
- Senior Member
- Posts: 58
If tags were to be included, a rule would have to be enforced that no inline styles could be included as those would break the display of the content, and all dimensional properties assigned in css for those tags would have to be entered for each tag that would be permitted to survive the stripping process.
Counting characters has it's advantages though because words can be contain all sorts of numbers of characters. The idea is to arrive at a uniform amount of content every time.
Please Log in or Create an account to join the conversation.
- GertJan van Schuppen
-
- Offline
- New Member
- Posts: 17
Lefteris Kavadas wrote: It is not that simple. When PHP counts the words to strip the text it cannot understand which part is HTML code and which is the actual text. This may result to incomplete HTML tags. Newer versions of Joomla! include a function for this but we have not tested it yet. You can try it using the following code:
<?php echo JHTML::_('string.truncate', ($this->item->introtext),20); ?>
Hi,
I have used this PHP code and it is working good! have a look here: www.madonnafanclub.nl/nieuws/actueel
Only a litle problem > as you can see all articles have a READ MORE (Lees meer) button. That's OK. But just above the button there are 3 dots... I think these come because of the introtext limitations. Is it possible to NOT show those dots?
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
<?php echo K2HelperUtilities::wordLimit($this->item->introtext, 20); ?>
Please Log in or Create an account to join the conversation.