You are here:  » Strip description


Strip description

Submitted by wesse249 on Wed, 2020-12-16 07:40 in

Hello David,

I placed the description text between these two no google index tags. I did this to tackle the duplicate content problem:

<?php
 
print tapestry_substr($product_main["description"],1200); 
?>

What i want is to strip the description text. Removing basic words from the description text (see example to strip) like with, that, you, See, how, real, becomes, when, the, and etc....

Example text to strip: Vivid, colourful pictures with sound that surrounds you See how real entertainment becomes when you combine the colour, contrast and clarity

After this i want to place back the text with comma's between the words above the related products block.

example text to place back: Vivid, colourful, pictures, sound, surrounds, entertainment , combine, colour, contrast, clarity

Submitted by support on Wed, 2020-12-16 08:17

Hi,

You could add a "Strip Words" filter to do this; add the following code to includes/filter.php

  /*************************************************/
  /* stripWords */
  /*************************************************/
  $filter_names["stripWords"] = "Strip Words";
  $filter_stripWords_words = array("with","that","you","see","how","real","becomes","when","the","and");
  function filter_stripWordsConfigure($filter_data)
  {
    print "<p>There are no additional configuration parameters for this filter.</p>";
  }
  function filter_stripWordsValidate($filter_data)
  {
  }
  function filter_stripWordsExec($filter_data,$text)
  {
    global $filter_stripWords_words;
    $text = preg_replace('/[ ]{2,}/',' ',strtolower(str_replace(","," ",$text)));
    $words = explode(" ",$text);
    $newWords = array();
    foreach($words as $word)
    {
      if (!in_array($word,$filter_stripWords_words)) $newWords[] = $word;
    }
    $text = ucwords(implode(", ",$newWords));
    return $text;
  }

...and then add a new Strip Words filter to the description field either per feed as required or as a global filter, and then re-import to apply the translations. Add to the $filter_strip_words array as required.

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by wesse249 on Mon, 2020-12-21 08:15

Hello David,

Is this also possible voor a new field (So i'd like to keep the orginal description which i place between the google no index tags) for example the field description short (which i need to create i think) or do you maybe have a solution?

And how can i place this new tekst above the related products block?

Thanks Jan

Submitted by support on Mon, 2020-12-21 08:58

Hello Jan,

Sure - you can add a new field say description_short as per the custom field instructions which can be found here. Then register and map the same field as description to this new field, and add the filter to the new field.

Then to display above Related Products, edit html/related.php and add the following to the very top of the script:

<div class='row'>
  <div class='small-12 columns'>
    <p><?php print $product_main["description_short"]; ?></p>
  </div>
</div>

Cheers,
David.
--
PriceTapestry.com

Submitted by wesse249 on Thu, 2020-12-24 09:20

Hello David,

It works great. One other question. Every word is now starting with a capital letter. Is it possible that during the import to the stripped description field all capital letters and punctuation marks being removed? And that the stripped description on the website is showing no capital letters?

I'd like to donate some money for your great assistance where can i do that?

Thanks Jan Roel

Submitted by support on Thu, 2020-12-24 09:36

Hello Jan,

Sure - the words are actually made Title Case using ucwords() in this line in the new filter:

     $text = ucwords(implode(", ",$newWords));

So to remove that (the words are already all lower case at this point), and in its place remove punctuation marks (except the commas separating the words) REPLACE this with:

    $text = preg_replace("/[^a-z,]/","",implode(", ",$newWords));

If there are other characters you want to permit, e.g. apostrophe, you can add it to the list of characters between the square brackets in the call to preg_replace e.g.

    $text = preg_replace("/[^a-z,']/","",implode(", ",$newWords));

You can make a support plus contribution here...

https://www.pricetapestry.com/supportPlus

Thanks so much!

Regards,
David.
--
PriceTapestry.com

Submitted by wesse249 on Thu, 2020-12-24 09:56

Thanks. But now all words are in one line. Is there a trick to solve this? See above related products.

{link saved}

Submitted by support on Thu, 2020-12-24 09:58

Ah sorry about that - the preg_replace would have removed the spaces..! Have a go with:

    $text = preg_replace("/[^a-z, ]/","",implode(", ",$newWords));

Cheers,
David.
--
PriceTapestry.com