Page 1 of 3
Short Product Description / Description Excerpt
Posted: Fri May 15, 2009 11:27 pm
by graf1771
Hi,
I'm creating a custom install for a client and am trying to pull a shortened version of the product description into the homepage and search page.
Is there a simple way to do this that doesn't requite database fiddling? I've gone through the controllers but probably missed something as I'm not very good with php...
thanks
Re: Short Product Description / Description Excerpt
Posted: Fri May 15, 2009 11:38 pm
by phpuk
Hi,
In the display area (template) use something like this:
Code: Select all
substr(strip_tags($query->row['description']),0,25) . "..."
Replace description with the name of the field you wish to truncate and the 25 with the number of characters you want to display before the ellipse ...
Phil.
Re: Short Product Description / Description Excerpt
Posted: Fri May 15, 2009 11:58 pm
by graf1771
That's the sort of thing I need, just I can't get the description to be pulled onto the pages I need, I tried this:
Code: Select all
<?php echo $products[$j]['description']; ?>
but it doesn't work - I'm guessing that I need to make a more fundamental change somewhere?
Re: Short Product Description / Description Excerpt
Posted: Tue Jun 16, 2009 9:39 pm
by d33p
phpuk wrote:Hi,
In the display area (template) use something like this:
Code: Select all
substr(strip_tags($query->row['description']),0,25) . "..."
Replace description with the name of the field you wish to truncate and the 25 with the number of characters you want to display before the ellipse ...
Phil.
I am trying this right now, but I am not a php-coder
In catalog/controller/product/product.php around line 133 i inserted
Code: Select all
'short_description' => substr(strip_tags($result['description']),0,50). "...",
I display it in view/theme/template/default/template/product/category.tpl with
Code: Select all
<?php echo $products[$j]['short_description']; ?>
Basically it works, but the tags are not being stripped yet. At
http://us3.php.net/manual/en/function.strip-tags.php it says, that squared brackets are used to exclude tags from being stripped. Does it have to do something with that?
Could any of you PHP-Guys please give me a hint?
Help's appreciated,
Thanks
Claus
Re: Short Product Description / Description Excerpt
Posted: Tue Jun 23, 2009 12:28 am
by d33p
Anybody?
Re: Short Product Description / Description Excerpt
Posted: Wed Jun 24, 2009 5:20 am
by readyman
Try this instead...
Code: Select all
'shortdescription' => html_entity_decode(substr($result['description'],0,50))."...",
Your above edits to the files don't seem to add up though... you need the make changes to category.php and category.tpl.
The category.tpl doesn't appear in controller/product/product.php as far as I can see.
Let me know if this works for you.
Re: Short Product Description / Description Excerpt
Posted: Thu Jun 25, 2009 6:26 pm
by d33p
Sorry, that was a typo. I meant to say that I edited both, the category.php and category.tpl and it basically works. My Problem is that the tags are NOT being stripped.
It's rather a lack of basic PHP-Knowledge-Kind-Of-Problem. If anybody could just give me a hint where to look for the problem I would try to find my way through.
Thank you in advance,
Claus
Re: Short Product Description / Description Excerpt
Posted: Fri Jun 26, 2009 2:25 pm
by readyman
Did this work for you? I'll post the files you need if you are still having issues.
Re: Short Product Description / Description Excerpt
Posted: Fri Jun 26, 2009 4:39 pm
by d33p
Sorry Readyman,
i somehow totally skipped the first part of your message... err
Your solution works fine, thanks a lot... I should get more into php I guess...
Have a nice weekend,
Claus
Re: Short Product Description / Description Excerpt
Posted: Sat Jun 27, 2009 12:20 am
by ThePath
Hi Readyman,
Im just wondering if you have a better solution to this issue. I followed instructions and came across some issues. One issue was it displays the text as is; that is to say if your first line of text is bold it will display bold in the short description, obviously the first line may change from bold to normal for different product descriptions, so it doesnt look good. Another issue I found was the 1st product to display a short description either failed to do so or displayed something weird. Another was the short description doesnt seem to get passed a carriage return in the main description and so stops short.
What would be perfect was if I could enter a short description in admin to be displayed. How would I go about this?
Thanks in advance!
Re: Short Product Description / Description Excerpt
Posted: Sat Jun 27, 2009 12:23 am
by d33p
Yes, custom fields in the product description would indeed be very, very helpful.
Re: Short Product Description / Description Excerpt
Posted: Sun Jun 28, 2009 2:18 pm
by readyman
@thepath - I'll look into adding a "short description" add-on.
It will require:
- adding a field in the database for the 'product summary'
- making the field in the admin pages to add content to it.
- retrieving and putting the summary in the product list in the front end.
Pretty straight forward.
@d33p - custom fields in the description? Sounds like it's something else entirely - can you elaborate on that one?
Re: Short Product Description / Description Excerpt
Posted: Sun Jun 28, 2009 11:02 pm
by ThePath
Nice one readyamn!
Simple for those familiar with the opencart structure and well versed in php. For a dumb bum like moi however not so straight forward Im afraid. Waaaa
Re: Short Product Description / Description Excerpt
Posted: Thu Jul 02, 2009 2:32 pm
by make-oc
Just a thought… why not use the "Meta Tag Description" -- could do the job ;-)
Re: Short Product Description / Description Excerpt
Posted: Sat Jul 04, 2009 3:42 pm
by readyman
Yep that's correct, it's exactly the same as the meta tag description, but it will just display in a different part of the template to just give you more control.
Re: Short Product Description / Description Excerpt
Posted: Thu Jul 09, 2009 6:46 am
by ThePath
Hey Readyman just wondering if there was any progress on this one.
Cheers
Re: Short Product Description / Description Excerpt
Posted: Sat Apr 10, 2010 12:49 am
by gxpratama
ThePath wrote:Hey Readyman just wondering if there was any progress on this one.
Cheers
Yeah, also in need of this capabilities now. Anyone knows how to do it the simple way in 1.4.6?
Regards,
Re: Short Product Description / Description Excerpt
Posted: Tue Jul 06, 2010 7:58 pm
by helenmarie
I am also wondering how to get a short description to display on the homepage, has anyone had any joy with this?
Helen
Re: Short Product Description / Description Excerpt
Posted: Tue Jul 06, 2010 10:52 pm
by Qphoria
1a. If using 1.4.8 or later, EDIT: catalog/controller/module/latest.php
1b. If using 1.4.7 or earlier, EDIT: catalog/controller/common/home.php
2. FIND:
3. AFTER, ADD:
Code: Select all
'description' => strip_tags(substr(html_entity_decode($result['description']),0,80))."...",
4a. If using 1.4.8 or later, EDIT: catalog/view/theme/default/template/module/latest_home.tpl
4b. If using 1.4.7 or earlier, EDIT: catalog/view/theme/default/template/common/home.tpl
5. FIND:
6. BEFORE, ADD:
Code: Select all
<?php echo $products[$j]['description']; ?>
Re: Short Product Description / Description Excerpt
Posted: Tue Jul 06, 2010 11:52 pm
by helenmarie
hi Q,
Thank you for your reply.
I am using 1.4.7