Announcement

Collapse
No announcement yet.

I want to display only the first 10 words from the full description

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    I want to display only the first 10 words from the full description

    It is possible to include a PHP statement which only displays the first 10 words of the full description in the store pages. This is useful if you are displaying a compact version of the product, and don't want the full description to appear.

    Simply click on the product description (in the 'Design' tab) that you want to shorten.

    Then locate the 'ProductDescription' variable in the layout code.

    Highlight that variable and replace it with the following code:

    <actinic:block php="true" >

    $sShort = "";

    $nCount = 0;

    $sOriginal = '<actinic:variable encoding="perl" name="ProductDescription" selectable="false" />';

    foreach(explode(" ", $sOriginal) as $sWord)

    {

    if ($nCount > 10)

    {

    $sShort .= "...";

    break;

    }

    $sShort .= $sWord . " ";

    $nCount++;

    }

    echo $sShort;

    </actinic:block>
Working...
X