Announcement

Collapse
No announcement yet.

First 10 words

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

    First 10 words

    Does anyone know of a way using the php code as per the AUG for the first 10 words to get the script to ignore the first word and then continue?

    Reason being as that all my product descriptions start with {Description} as I use tabber and when I use the First 10 Words code it includes {Description}.

    Have had a look at the code but unfortunately my understanding of PHP isn't that good!

    TIA

    Kathy
    Kathy Newman

    #2
    Kathy,
    Try 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 != 0) 
    { 
    if ($nCount > 10)
    {
    $sShort .= "...";
    break;
    }
    $sShort .= $sWord . " ";
    }
    $nCount++;
    }
    echo $sShort;
    </actinic:block>
    This simply skips the first word and then counts up to 10 words before displaying the "...".
    This obviously means that it's only going to show 9 words in the example above. For 10 words you'd need to change the
    Code:
    if ($nCount > 10)
    to
    Code:
    if ($nCount > 11)
    Hope this helps.

    *example code taken and amended from KB article
    Fergus Weir - teclan ltd
    Ecommerce Digital Marketing

    SellerDeck Responsive Web Design

    SellerDeck Hosting
    SellerDeck Digital Marketing

    Comment


      #3
      Thanks for that Fergus - however I think I didn't give enough detail in original post. What I need the php to do is ignore upto and including the first } character.

      Your code worked fine except if there was no space after the first } it loses the first of the words I want to keep!

      Kathy
      Kathy Newman

      Comment


        #4
        Hi Kathy,
        It would be possible to get the first word to not show the first 13 characters (for {description}) however is it not possible to simply put a space after the }?
        Fergus Weir - teclan ltd
        Ecommerce Digital Marketing

        SellerDeck Responsive Web Design

        SellerDeck Hosting
        SellerDeck Digital Marketing

        Comment


          #5
          Originally posted by kathynewman View Post
          Thanks for that Fergus - however I think I didn't give enough detail in original post. What I need the php to do is ignore upto and including the first } character.

          Your code worked fine except if there was no space after the first } it loses the first of the words I want to keep!

          Kathy
          use the trim command

          Code:
          <actinic:block php="true" >
          $sShort = "";
          $nCount = 0;
          $sOriginal = '<actinic:variable encoding="perl" name="ProductDescription" selectable="false" />';
          $sOriginal = trim(  $sOriginal ,  "{Description}" );
          foreach(explode(" ", $sOriginal) as $sWord)
          
          {
          
          if ($nCount > 10)
          
          {
          
          $sShort .= "...";
          
          break;
          
          }
          
          $sShort .= $sWord . " ";
          
          $nCount++;
          
          }
          
          echo $sShort;
          </actinic:block>
          This assumes that you always used Description and not description

          Malcolm

          SellerDeck Accredited Partner,
          SellerDeck 2016 Extensions, and
          Custom Packages

          Comment


            #6
            or to always miss out the
            HTML Code:
            {description}
            from the first word you could use
            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;
            }
            if ($nCount == 0) {
                $sShort .= substr($sWord,13) . " ";
            }
            else {
            $sShort .= $sWord . " ";
            }
            $nCount++;
            }
            echo $sShort;
            </actinic:block>
            Very quick, clunky solution. Note: this will only work properly if all descriptions start with {description}.
            If there are other details within the tabber then perhaps a more elegant solution would be required.
            Fergus Weir - teclan ltd
            Ecommerce Digital Marketing

            SellerDeck Responsive Web Design

            SellerDeck Hosting
            SellerDeck Digital Marketing

            Comment


              #7
              I've posted how to do this on my Tabber support forum. See http://www.drillpine.biz/forums/view...php?f=12&t=257
              Norman - www.drillpine.biz
              Edinburgh, U K / Bitez, Turkey

              Comment

              Working...
              X