Hi Dave,
I am trying to add a readmore for product descriptions for the html/product.php i am using Jquery library i have javaScript in place and works as it should.
Trouble i am having is my descriptions are missing charactors. Is there a way that i can display the first 400 charactors after a space then wrap the rest of the product description in a span?.
This is what i got so far but just not working as expected?
<?php if ($mainProduct["description"]): ?>
<? $ReadmoreDescription = substr($mainProduct["description"],400,6000) . " <a id='readless'href='#'>Read Less!</a>"; ?>
<?php aliveTextLinks($trimText, $DESCR_ALIVING_RULES); ?>
<?php
$breakLimit = 400;
if (strlen($mainProduct["description"]) > $breakLimit)
{
$breakOffset = strpos($mainProduct["description"]," ",$breakLimit);
if ($breakOffset !== false)
{
$mainProduct["description"] = substr($mainProduct["description"],0,$breakOffset).
" <a id='readmore' href='#'>Read More!</a>";
}
}
?>
<div id="product_desc">
<?php print $mainProduct["description"]; ?>
<span id="box"><?php print $ReadmoreDescription ; ?></span>
</div>
Kind Regards
Darren
Hi Dave,
Many thanks for quick reply but that did not work what i need to achieve is to display the full product description showing the first 400 charactors then the rest of the description is hidden inside span so when user click readmore link the rest of the description is diplayed and when the user click link readless the span is hidden again.
I was thinking could we not just count chars on description and after the 400th charactor the space after this is to replace it with the hidden span? then the javascript can do the rest
Kind Regards
Darren
Hi Darren,
If I understand the requirement correctly, that should be what is achieved by the above code.
Could you perhaps view the source being generated by the modification (using the browser's View > Source menu), and let me know how the HTML being generated differs from the output you require then we can have another look at the code...
Cheers,
David.
Hi Dave,
here is my test servers link to new PT install i have added full description as well so you can see i am loosing some text on description.
can you remove my link please Dave from this post
{link saved}
Kind Regards
Darren
the code i am using is my oringinal one
Hi Darren,
As you are including both versions are they conflicting by virtue of class / ID name? Could you post my version only and let me know when that's online...
Cheers,
David.
Hi Darren,
There was interaction going on (only the first Read More / Read Less would work)... could you email me your modified files to take a look at, i'll try to fix it up based on the output being generated...
Cheers,
David.
Hi Darren,
Check out this plugin for Jquery:
http://www.reindel.com/truncate/
Should do what you want.
Cheers.
Keeop
Hi Dave,
Many thanks that worked a treat Dave.
Kind Regards
Darren
Hi Darren,
I would construct $ReadmoreDescription at the same time as extracting the first 400 characters on a space. Assuming that your JavaScript is working, have a go with something like this;
<?php if ($mainProduct["description"]): ?>
<?php aliveTextLinks($trimText, $DESCR_ALIVING_RULES); ?>
<?php
$breakLimit = 400;
if (strlen($mainProduct["description"]) > $breakLimit)
{
$breakOffset = strpos($mainProduct["description"]," ",$breakLimit);
if ($breakOffset !== false)
{
$mainProduct["description"] =
substr($mainProduct["description"],0,$breakOffset).
" <a id='readmore' href='#'>Read More!</a>";
$ReadmoreDescription =
substr($mainProduct["description"],$breakOffset).
" <a id='readless' href='#'>Read Less!</a>";
}
}
?>
<div id="product_desc">
<?php print $mainProduct["description"]; ?>
<span id="box">
<?php print $ReadmoreDescription; ?>
</span>
</div>
<?php endif; ?>
Note that I added the endif; statement - if that's already in place don't duplicate it otherwise it would cause a PHP syntax error...
Hope this helps!
Cheers,
David.