Hi David
Is it possible to code the product description so that if the description does not meet X amount of characters the script will output what description is available plus print the contents of a default .txt file to a combined maximum amount of characters.
Chris
Thanks David
Boy that was quick for a Friday afternoon.
Is it OK to use in search results and just change $mainProduct to $Product ?
Chris
Yes, no probs - $product instead of $mainProduct.
Cheers,
David.
hi david
is it possible to make this script cut the description at the full stop closest to say 800 characters?
regards
Phil Stone
www.buy24-7.net
Hi Phil,
Do you mean including the mod described above to load additional description content from a file, or just to crop the description as it is at the nearest full stop to X characters?
Cheers,
David.
--
PriceTapestry.com
sorry yes just to crop the description at the full stop nearest to x characters. was also wondering do you see there being many changes to the beta release when the new script is launched?
thanks a million
regards
Phil Stone
www.buy24-7.net
Hi Phil,
This can be done easily with a modification of the new tapestry_substr() function from the beta distribution (will work in any version). Add the following code to the end of your includes/tapestry.php, immediately before the closing PHP Tag:
function tapestry_substrChar($text,$char,$length,$append="")
{
if (strlen($text) > $length)
{
$breakOffset = strpos($text,$char,$length);
if ($breakOffset !== false)
{
$text = substr($text,0,$breakOffset).$append;
}
}
return $text;
}
Then to use this it, for example as above where the main description is displayed by line 12 of html/product.php; in place of:
<p><?php print $mainProduct["description"]; ?></p>
use:
<p><?php print tapestry_substrChar($mainProduct["description"],".",800); ?></p>
Cheers,
David.
--
PriceTapestry.com
Hi Chris,
Yes - that's pretty straight forward. The description is currently displayed by the following code in html/product.php beginning at line 12:
<?php if ($mainProduct["description"]): ?>
<p><?php print $mainProduct["description"]; ?></p>
<?php endif; ?>
If you just want to use a single description.txt file to padd out all descriptions, then simply modify the above code as follows:
<p>
<?php
$minLength = 400; // change this to the number of characters required
print $mainProduct["description"];
if (strlen($mainProduct["description"]) < $minLength)
{
$extra = get_file_contents("description.txt");
$extra = substr($extra,0,$minLength-strlen($mainProduct["description"]));
print $extra;
}
?>
</p>
This code would use a file called description.txt in the main Price Tapestry directory.
Hope this helps!
Cheers,
David.