You are here:  » Banner ad inside search results


Banner ad inside search results

Submitted by senaite on Wed, 2014-04-09 15:49 in

Hi David,
Is there any way to insert banner ad codes into the search results?

Search results
1
2
3
4
5
Ad code here
6
7
8
9
10

Thank you

Submitted by support on Fri, 2014-04-11 11:04

Hi senaite,

Sure, in html/searchresults.php, look for this code at line 6:

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

...and REPLACE with:

    <?php foreach($searchresults["products"] as $k => $product): ?>
      <?php if ($k==5): ?>
      <tr>
        <td colspan='3'>
           <!-- Ad code here -->
        </td>
      </tr>
      <?php endif; ?>

Cheers,
David.
--
PriceTapestry.com

Submitted by senaite on Tue, 2014-04-22 22:18

Is it possible to display the ad after the listings if listings less than 5?

Search results:
1
2
3
Ad

or if only one listing

1
Ad

Thanks

Submitted by support on Wed, 2014-04-23 07:58

Sure,

In the same file, locate the end of the foreach loop around line 33:

  <?php endforeach; ?>

...and REPLACE with:

  <?php endforeach; ?>
  <?php if ($k 5): ?>
    <tr
      <td colspan='3'>
         <!-- Ad code here -->
      </td>
    </tr>
  <?php endif; ?>

Finally, to avoid duplicating your ad code, the best thing to do would be to save it in a new file called html/adcode.php (no need for PHP tags in the file) and then in place of each

<!-- Ad code here -->

...use:

<?php require("html/adcode.php");

Cheers,
David.
--
PriceTapestry.com

Submitted by stevebi on Wed, 2015-04-29 22:56

Hi David,

How could we modify the above code, so that in product page and specifically at prices table, when there are more than 3 merchants the banner to appear after the third merchant.

Cheers

S

Submitted by support on Thu, 2015-04-30 08:52

Hi Steve,

Sure, in html/prices.php look for the opening line of the loop around line 43:

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

...and REPLACE with:

  <?php foreach($prices["products"] as $k => $product): ?>
  <?php if ($k==2): ?>
    <tr>
      <td colspan='<?php print ($prices_showVoucherCodes?"5":"4"); ?>'>
        <!-- Ad code here -->
      </td>
    </tr>
  <?php endif; ?>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by stevebi on Thu, 2015-04-30 09:12

Hi David,

The only code near the above is at line 27

<?php
 
foreach($prices["products"] as $price_product): 
?>

Should I modify this?

Thanks a lot

Steve

Submitted by support on Thu, 2015-04-30 09:20

Hi Steve,

I just checked back through email for the last copy I have from you and in your case REPLACE the line that you have identified with;

  <?php foreach($prices["products"] as $k => $price_product): ?>
  <?php if ($k==2): ?>
    <tr>
      <td colspan='<?php print ($prices_showVoucherCodes?"5":"4"); ?>'>
        <!-- Ad code here -->
      </td>
    </tr>
  <?php endif; ?>

Cheers,
David.
--
PriceTapestry.com

Submitted by stevebi on Thu, 2015-04-30 11:11

Thank you very much for your support David!

Submitted by wesse249 on Fri, 2015-05-15 10:45

hi,

is this solution also for 15/01A ?

Because it doesn't show up by me.

Greetings JR

Submitted by support on Fri, 2015-05-15 11:05

Hello JR,

For search results, not quite - because html/searchresults.php in 15/01A uses the responsive grid instead of a table layout for search results. So to insert ad code after the 5th result, 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==5): ?>
      <div class='row'>
        <div class='small-12 columns'>
          <!-- Ad code here -->
        </div>
      </div>
      <?php endif; ?>

Version for html/prices.php is current. Note that the <!-- Ad code here --> is commented so until that is replaced with actual displayed markup there won't be any visual change to the page, but you should be able to view the comment using your browser's View > Source menu to confirm working correctly.

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Wed, 2016-08-03 11:26

Hi David,

Thanks for your help yesterday getting the product price table banners to work. I wondered if you could suggest a way I could randomise the banner displayed (similar to the mod detailed in node 2442). Initially, I would like to display a random ad relating to one of the merchants whose prices is displayed in the (product) price table but Ideally, it would be great if I could alternatively display a random ad chosen from all merchants or from merchants not appearing in the price table results since this would allow me to manually switch the banners depending on the conversion rate.

Thanks in advance.

Best Regards
Chris

Submitted by support on Wed, 2016-08-03 12:14

Hi Chris,

I notice you are currently using:

<?php require("html/adcode.php");?>

If you have ad code for all merchants on your site, firstly create separate files for each named "html/adcode_Merchant Name.php" e.g.

html/adcode_Merchant 1.php
html/adcode_Merchant 2.php

Then in place of the above, for the first case of selecting the ad code for a random merchant that does feature in the price comparison table, have a go with:

<?php
  $merchants 
= array();
  foreach(
$prices["products"] as $p)
  {
    
$merchants[] = "'".database_safe($p["merchant"])."'";
  }
  
$in implode(",",$merchants);
  
$sql "SELECT merchant FROM `".$config_databaseTablePrefix."products` WHERE merchant IN (".$in.") ORDER BY rand() LIMIT 1";
  if (
database_querySelect($sql,$rows))
  {
    
$merchant $rows[0]["merchant"];
    require(
"html/adcode_".$merchant.".php");
  }
?>

Then when you want to move to showing an ad for a merchant _not_ featured in the price comparison table, simply change:

WHERE merchant IN

...to:

WHERE merchant NOT IN

If you don't yet have adcode for all merchants then you can add an additional WHERE clause containing another IN list to ensure that only merchants for which you have ad code are selected. To do this for the first case, use:

    $sql = "SELECT merchant FROM `".$config_databaseTablePrefix."products` WHERE merchant IN ('Merchant 1','Merchant 2') AND merchant IN (".$in.") ORDER BY rand() LIMIT 1";

And to convert this to the second case;

    $sql = "SELECT merchant FROM `".$config_databaseTablePrefix."products` WHERE merchant IN ('Merchant 1','Merchant 2') AND merchant NOT IN (".$in.") ORDER BY rand() LIMIT 1";

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Wed, 2016-08-03 14:18

Hi David,

Thanks as always for your super quick response. I've modified the code as detailed above (and added adcode files for every retailer) but nothing is displayed.

I'm guessing it's due to the first line of code which looks wrong as it has a reference to a specific product ("Sony KDL50W756CSU").

Would be grateful if you could confirm what this line of code should be.

Thanks in advance.

Best regards
Chris

Submitted by support on Wed, 2016-08-03 14:27

Sorry about that Chris! I was testing the code on a live server so added the IF conditional so that the output was only displayed on the page I was testing on...!

Corrected above.

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Wed, 2016-08-03 16:19

Hi David,

Thanks for the update which I have implemented. Unfortunately, no banners are displayed still. Also, I notice only 2 rows of prices are displayed. I can see the line limit is controlled by line 180 of the code but even when I change this to 10 the banners still do not appear. The code I have is:

{code}

Would be grateful if you could suggest what could be going wrong and how it might be able to resolve it.

Thanks in advance.

Regards
Chris

Submitted by support on Wed, 2016-08-03 16:26

Hi Chris,

Please could you email me as an attachment the file where you have included the code and I'll follow up by email with you...

Thanks!
David.
--
PriceTapestry.com