You are here:  » use my own descriptions

Support Forum



use my own descriptions

Submitted by jonny5 on Sun, 2010-10-10 16:49 in

Hi david , im trying to add my own descriptions to the product page so have the below code (like the logo display code) but i want the description displayed per product not per merchant, i assume i need to change the bracketed "merchant" to "product" but its not working

i guess its something simple :)

<?php
      
if (file_exists("mydescription/".$product["merchant"]))
      {
        require(
"mydescription/".$product["merchant"]);
      }
      else
      {
        print 
"&nbsp;";
      }
      
?>

Submitted by support on Sun, 2010-10-10 17:25

Hi Jonny,

Wherever you have $product["merchant"] you will always have $product["name"] available so you can simply use that instead within your code.

However, it may be easier to make your description filenames use the normalised name ($product["normalsed_name"] which is the version that appears in the URL and doesn't contain any special characters that might make awkward filenames. Perhaps easier still, to determine the exact name to use, simply copy it from the URL, including even including the .html extension and then in your code, you would use:

<?php
  $mydescriptionFilename 
"mydescription/".tapestry_hyphenate($product["normalised_name"]).".html";
  if (
file_exists($mydescriptionFilename))
  {
    require(
$mydescriptionFilename);
  }
  else
  {
    print 
"&nbsp;";
  }
?>

This way, the filenames in your /mydescription/ folder simply match exactly the product URL after /product/

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by jonny5 on Sun, 2010-10-10 18:19

cheers david , still cant get it to display though

im using the code u posted with the .hyml extension as the file name appears in the browser

Submitted by support on Mon, 2010-10-11 08:54

Hi Jonny,

Sorry - I just realised that if you are wanting to display this in the main product area on the products page, in place of

$product["normalised_name"]

...it would need to be:

$mainProduct["normalised_name"]

That should be all it is...

Cheers,
David.
--
PriceTapestry.com

Submitted by jonny5 on Mon, 2010-10-11 10:25

yep , working now , cheers

Submitted by jonny5 on Mon, 2010-10-11 11:21

ok last thing , i also want the new desciptions on the featured products but only showing 250 characters at the most

so the below code works but i just need to cut the decriptions down to 250 characters, not quite sure where to add it

<?php
  $descriptionsFilename 
"descriptions/".tapestry_hyphenate($product["normalised_name"]).".html";
  if (
file_exists($descriptionsFilename))
  {
    require(
$descriptionsFilename);
  }
  else
  {
    print 
"&nbsp;";
  }
?>

Submitted by support on Mon, 2010-10-11 11:27

Hi Jonny,

Try the following - this will break your description content on the first word boundary after 250 characters (looks nicer than breaking mid-word!)

<?php
  $descriptionsFilename 
"descriptions/".tapestry_hyphenate($product["normalised_name"]).".html";
  if (
file_exists($descriptionsFilename))
  {
    
$descriptionText file_get_contents($descriptionsFilename);
    
$breakLimit 250;
    if (
strlen($descriptionText) > $breakLimit)
    {
      
$breakOffset strpos($descriptionText," ",$breakLimit);
      if (
$breakOffset !== false)
      {
        
$descriptionText substr($descriptionText,0,$breakOffset);
      }
    }
    print 
$descriptionText;
  }
  else
  {
    print 
"&nbsp;";
  }
?>

Cheers,
David.
--
PriceTapestry.com

Submitted by jonny5 on Mon, 2010-10-11 11:33

many thanks

Submitted by Leo on Mon, 2010-10-11 15:04

Hi David,

I use this descriptions text to a lot. Is this possible on search keywords.
Lets say search.php?q=Searchname we get the description of Searchname?

Now i use something like this.
if (($parts[0]=="brand") && ($page==1))

Leo

Submitted by Leo on Tue, 2010-10-12 07:41

Hi David,

Guess something has goes wrong with my last post, will try again.

I am bussy with navigation based on search results.

Is it possible to have own descriptions with search results?
Like you search for Diesel, search.php?q=Diesel you get description txt file for Diesel?

Thanks
Leo

Submitted by support on Tue, 2010-10-12 08:23

Hi Leo,

Sure - within search.php you can either use the value of $q directly to load a description file, however since there can be problems with : in a filename replace it with _ before using the value of $q. Have a go with something like this:

  $filename = "searchdescriptions/".str_replace(":","_",$q).".html";
  if (file_exists($filename))
  {
    require($filename);
  }

...and then make a searchdescriptions/ folder, and inside place your description files names exactly as the query plus .html, for example:

searchdescriptions/Diesel.html
searchdescriptions/brand_Nike_.html

Cheers,
David.
--
PriceTapestry.com

Submitted by Leo on Tue, 2010-10-12 09:11

Hi David,

Thanks! Works perfect.

Forgat to ask that i just need something like this (($page==1))) that its showing only on the first page?

Leo

Submitted by support on Tue, 2010-10-12 09:16

Hi Leo,

Wrap the block of code within an IF statement to restrict to page 1 - e.g.

if ($page==1)
{
  $filename = "searchdescriptions/".str_replace(":","_",$q).".html";
  if (file_exists($filename))
  {
    require($filename);
  }
}

Cheers,
David.
--
PriceTapestry.com