Page 1 of 2
Truncated description text
Posted: Sat Oct 15, 2011 4:27 am
by monostudio
New to this board and working on a couple of sites at the moment. I am trying to extend the truncated text in the product listings - where you can view by list or grid so we can get a full sentence in there and it doesn't get cut off (in list view).
Trying to avoid this sort of thing: Vivaspin centrifugal concentrators are disposable ultrafiltration devices for the concentration o..
Hope you can help - am working in 1.5.1
Cheers
Tim
Re: Truncated description text
Posted: Sat Oct 15, 2011 7:12 am
by JAY6390
Hi Tim. Here's a little function you can use (put it at the top of the template file
Code: Select all
<?php
if(!function_exists('get_snippet')) {
function get_snippet($sentence, $count = 5, $separator = ' ') {
$count = (int) $count;
if(!$count) return '';
$words = array_chunk(explode($separator, $sentence), $count);
return implode($separator, $words[0]);
}
}
?>
Then for the text, you just wrap it in parentheses and put get_words before it, optionally specifying the word count
For example, you could change
Code: Select all
<?php echo $product['description']; ?>
to
Code: Select all
<?php echo get_snippet($product['description'], 15); ?>
Re: Truncated description text
Posted: Tue Oct 18, 2011 5:14 am
by monostudio
Thanks for the rapid reply Jay - sorry don't want to break it, so which file do you change? Sorry to ask but am new to this.
Thanks Tim
Re: Truncated description text
Posted: Tue Oct 18, 2011 5:17 am
by JAY6390
It depends which page. The main ones I'm guessing will be
Code: Select all
/catalog/view/theme/your-theme-name/template/product/product.tpl
/catalog/view/theme/your-theme-name/template/product/category.tpl
/catalog/view/theme/your-theme-name/template/product/manufacturer_info.tpl
/catalog/view/theme/your-theme-name/template/product/search.tpl
Re: Truncated description text
Posted: Fri Oct 21, 2011 6:51 am
by monostudio
Thanks for the input - have been working on the category.tpl. The code seems to work to shorten the number of words - ie less than 15 - if I increase this number nothing seems to happen.
ie <?php echo get_snippet($product['description'], 30); ?>
Perhaps there is something else preventing any more words to be added. Test site is
generonshop.co.uk/generon - still work in progress.
Re: Truncated description text
Posted: Fri Oct 21, 2011 5:18 pm
by JAY6390
Are you sure there are more than 15 words?
Re: Truncated description text
Posted: Fri Oct 21, 2011 5:44 pm
by monostudio
Hi Jay - thanks for all your help on this. Go to:
http://generonshop.co.uk/generon/index. ... path=71_72
You will see the description at the top that is being used for all this range of products at the moment.
The full description:
The BJP concentrates urine through the absorption of water by absorbent pads located on the underside of an ultrafiltration membrane. Bence Jones protein will be retained on the membrane surface in the front compartment of the BJP unit because it has a 7.5 kDa MWCO membrane, a molecular weight cut-off far from the molecular weight of Bence Jones protein itself.
The truncated text cuts as:
The BJP concentrates urine through the absorption of water by absorbent pads located on the under..
It's 15 + a bit words - perhaps I am referring to the wrong text or something?
Cheers
Tim
Re: Truncated description text
Posted: Fri Oct 21, 2011 5:48 pm
by JAY6390
Ah, the problem will be that it contains HTML actually. it won't work with HTML content
Re: Truncated description text
Posted: Fri Oct 21, 2011 5:53 pm
by monostudio
So you reckon this text snippet cannot be expanded to show a bit more?
Re: Truncated description text
Posted: Fri Oct 21, 2011 5:56 pm
by JAY6390
Hi Tim. The problem is that the snippet cuts off the end tags of the HTML, so it could totally mess up your page. I would therefore advise against this
Re: Truncated description text
Posted: Fri Oct 21, 2011 6:05 pm
by monostudio
Last question before I abandon this ;-) - am playing with CSS in firebug - could this tweaked to show more or even have no description snippet at all to clean the listings up? Thanks T
Re: Truncated description text
Posted: Fri Oct 21, 2011 6:21 pm
by JAY6390
You can certainly get rid of the description snippets sure. As for the css option, I don't think there's any way of doing this with that
Re: Truncated description text
Posted: Thu Dec 01, 2011 1:12 am
by travoltron
The file in question you'd like to update is: /catalog/controller/product/category.php
Line 186:
Code: Select all
'description' => substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..',
Change to:
Code: Select all
'description' => substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 900) . '',
Increasing the number of parsed characters from 100 to 900 (or whatever you need it to, and if you add ending punctuation in your descriptions, remove the
and change it to
, to remove the trailing ellipses.
Hope it helps!
Re: Truncated description text
Posted: Tue Feb 21, 2012 3:10 pm
by albsim81
Thank you.
But, in your opinion ther is a problem of duplicate content now, between product and category page?
Re: Truncated description text
Posted: Thu Feb 23, 2012 12:10 am
by monostudio
Thanks for the input - will have a look at some point again. Been diverted onto other areas of Opencart to modify now!
Cheers
Re: Truncated description text
Posted: Mon Jul 02, 2012 4:55 pm
by billshakes
I have been looking for a similar solution and followed travoltron php change to allow full description text (no truncation) in list view which is great but I would also like to show the audio player in list view that I have in full product view>source>html.
e.g.
<p>
<object data="dewplayer.swf" height="20" id="dewplayer" name="dewplayer" type="application/x-shockwave-flash" width="200"><param name="movie" value="dewplayer.swf" /><param name="flashvars" value="mp3=../sampleguitar/mp3/test1.mp3" /><param name="wmode" value="transparent" /></object></p>
Is it possible to show the individual product audio flash player in the List view?
Any help greatly appreciated!
Toby
Re: Truncated description text
Posted: Sun Oct 13, 2013 4:46 pm
by arthurmild
To stop/edit trunctation of product description in OpenCart 1.5.6
In catalog/controller/product/category.php
search for the line
Code: Select all
$this->data['products'][] = array(
then
change :
Code: Select all
'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..',
to:
Code: Select all
'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 999),
the
999 is the number of characters that will display before being truncated, so alter this to suit yourself
The
. '..' at the end of the original line is what displays after truncation,
so if you wanted truncation, but not the default dots you could to amend this to e.g.
this would be the place to do it.
Re: Truncated description text [SOLVED]
Posted: Wed Aug 31, 2016 6:07 pm
by maxxpaul
Finally I managed to find a solution to this and it's working beautifully.
I know this is an old thread but there might be people who still use OpenCart 1.5.6.4.
Also I wanted to make a contribution to the community.
So .... in order to truncate the description text in product lists to only to full words, and only if the initial string's length is larger than the wanted one, here is the new code.
Find in:
in catalog/controller/product/ folder, in these 4 files:
category.php
manufacturer.php
search.php
special.php
the following line:
Code: Select all
'description' => substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..',
(assuming 100 is the default value, if not, search only for the first part of the line)
And replace with:
Code: Select all
'description' => (strlen(utf8_decode(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))))> 400 ? mb_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, mb_strrpos(mb_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 400, 'UTF-8'), ' ', 0, 'UTF-8'), 'UTF-8') : strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))) . '...',
Adjust the 400 value to your needs. Keep in mind that, using the default layout / template, the product listing in category has a lower width (because on one side there is the categories column), and in product, search and special has the full with of the content column.
Depending on the font used, you might get 2 1/2 rows of text in special.php, search.php and manufacturer.php using a value of
400 and a little more than that using
350 in category.php
Re: Truncated description text
Posted: Sat Sep 03, 2016 8:04 am
by IP_CAM
I just tried it with the files, and it seems to work well in my latest v.1.5.6.5_rc Test Shop. And looks much better too !
It only does not work on the product Page, for related items, where I added a
$desc Variable - calling the
$description Value, to add the Description to the related items also. So, I modified your 'content' accordingly, to match the above variable, but there, it presents an error, and the entire page does not longer display. But since I don't need to have it in the related Products, because of lots of free space, I just don't use it there anyway!
Code: Select all
'desc' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 240) . '.',
Sample Page:
http://www.gratis-anzeiger.com/shop/ind ... ry&path=33
Don't look at the Words, or try to understand the meaning, they are auto-generated!
Still, Google, Amazon, & Co. seemengly indexes them, on a steady pace!
Thank you !
Ernie
PS: OC v.1.5.6.x is not old, it's just grown-up!
http://www.merriam-webster.com/dictiona ... E2%80%93up
Re: Truncated description text
Posted: Tue Sep 20, 2016 11:54 am
by jyeann
Hi,
Is there a way to truncated the product name? currently on version '2.0.3.1' .
thanks.