You are here:  » Banners in search results


Banners in search results

Submitted by wilkins on Fri, 2015-11-13 11:58 in

Hi David

I dont know if this is possible, I would like to place banners within the search results

ie the search results produce 30 results I would like to place a banner after every 10 results on that page.

Is that possible

Using the latest version of PT

Brent

Submitted by support on Fri, 2015-11-13 12:51

Hello Brent,

Sure! In html/searchresults.php look for the following code at line 7:

    <?php foreach($searchresults["products"] as $product): ?>

...and REPLACE with:

    <?php foreach($searchresults["products"] as $k => $product): ?>
      <?php if ($k && !($k 10)): ?>
      <div class='row'>
        <div class='small-12 columns'>
          <!-- BANNER AD CODE HERE -->
        </div>
      </div>
      <?php endif; ?>

...and add your banner code where indicated by the comment...

Cheers,
David.
--
PriceTapestry.com

Submitted by stevebi on Sun, 2015-12-20 08:03

Hello David,

I have applied successfully the code that you provided above.

I just wanted a small modification.

At my search results page I provide 12,24,36 results per page.

I wanted when someone selects

*12 results, the banner to appear ONLY after the 6th product
*24 results, the banner to appear ONLY after the 12th product
*36 results, the banner to appear ONLY after the 18th product

Cheers

Steve

Submitted by support on Mon, 2015-12-21 09:15

Hello Steve,

I see that your results per page modification uses the $show variable, so you can use this divided by 2 as the trigger value, so for example where you have the following code from the second line of the replacement:

       <?php if ($k && !($k 10)): ?>

...REPLACE with:

       <?php if ($k && !($k % ($show 2))): ?>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by stevebi on Mon, 2015-12-21 09:49

Hello David,

Your modification works great!!!

Once more I would like to thank you for your great support and wish you Merry Christmas and a Happy New Year.

Cheers

Steve

Submitted by stevebi on Mon, 2015-12-21 19:44

Hello David,

Just noticed that at related products I am getting the following error

Notice: Undefined variable: show in searchresults.php on line 102

Thank you very much

Steve

Submitted by stevebi on Mon, 2015-12-21 19:46

And also the banners appear after every product

I will reverse it until you are able to check it

Thank you

Steve

Submitted by support on Tue, 2015-12-22 11:13

Hi Steve,

Ah - $show won't be set when html/searchresults.php is being used to display Related Products - no problem - add the following snippet at the very top of the file:

<?php
  
if (!isset($show)) $show 12;
?>

Of course, if you did want to display a banner after the related products then setting $show to 3 at this point would do the trick...

Cheers,
David.
--
PriceTapestry.com