You are here:  » Readmore On product descriptions

Support Forum



Readmore On product descriptions

Submitted by webie on Mon, 2009-07-27 12:25 in

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) . "&nbsp;<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).
"&nbsp;<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

Submitted by support on Mon, 2009-07-27 13:06

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).
  "&nbsp;<a id='readmore' href='#'>Read More!</a>";
$ReadmoreDescription =
  substr($mainProduct["description"],$breakOffset).
  "&nbsp;<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.

Submitted by webie on Mon, 2009-07-27 13:46

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

Submitted by support on Mon, 2009-07-27 13:50

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.

Submitted by webie on Mon, 2009-07-27 14:16

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

Submitted by support on Mon, 2009-07-27 14:27

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.

Submitted by webie on Mon, 2009-07-27 14:40

Hi Dave,

Your version is posted

Kind Regards

Darren

Submitted by support on Mon, 2009-07-27 14:59

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.

Submitted by Keeop on Mon, 2009-07-27 15:35

Hi Darren,

Check out this plugin for Jquery:

http://www.reindel.com/truncate/

Should do what you want.

Cheers.
Keeop

Submitted by webie on Mon, 2009-07-27 21:54

Hi Dave,

Many thanks that worked a treat Dave.

Kind Regards

Darren