Integrating Adsense On Classifieds Sites

Discussion in 'Site Marketing' started by seymourjames, Mar 23, 2011.

  1. seymourjames All Hands On Deck

    Something to be aware of

    A. Classifieds Site - Homepage - AdSense Help

    Can't believe I never saw this before. And with some minor customization it is achievable at the template level. I am at least hoping it enhances the revenue stream for adsense.

    Here is an example I have put on an estate agents site for French property but the principle remains for general classifieds and the implementation.

    Latest Listings For Property In France

    And I know it is ugly but I will style it later nicely.
  2. EnergyFreak Customer

    It's funny that you mentioned it, I just saw it today as well when I was playing around in Adsense. I think this came out recently because I never saw it before, it is certainly an interesting approach and I will most likely adapt it as well.

    Still thanks for sharing.
  3. seymourjames All Hands On Deck

    It turns out to be relatively simple to do when you know how on showlistings but there are some gotchas like getting adsense to appear on searchresults.php and empty categories, especially so if results pages are being excluded by robots.txt - I have worked out a way round that. In all it is not quite as straightforward as I was hoping but it is done now.
  4. EnergyFreak Customer

    I was thinking of adding a {foreach} loop as suggested in previous posts. It would display Adsense every 5 ads in showlistings.php but I did not get it to work yet.
  5. Mike-N-Tosh Owner

    That is new within the Google adsense help, however it isn't new to this forum and has been discussed a few times. Eric provided the code to integrate this within your showlistings template.

    Code:
    {if $smarty.foreach.foo.index % 5 == 0}
       Your ad code here
    {/if}
    Unfortunately, he didn't elaborate on the actual use of the code, so I will.
    I haven't tried this with the showlistings.tpl template which is the default, only the showlistings2.tpl which is the one with the short description in it. Right after this line which starts the display of the individual listings.
    {foreach from=$results item="entry" name="results"}
    Put the first line of Eric's code:
    {if $smarty.foreach.results.index % 5 == 0} <== replace "foo" with the foreach "from" name
    Then put in your ad code. You should probably put the code within a div and add styling so that it matches your ad displays

    After your ad code put this:
    {else}
    Then, leave all of the ad listing display code as is, but right BEFORE
    {foreachelse}
    End your if statement like this:
    {/if}

    *NOTE: The if statement actually counts itself in the index count, so you need to change the number to one more than the number of listing ads you want displayed before another display ad. So in the case you want to show it after 5 ads the first line should be % 6. Also, because the logic is set to == 0, this will show an ad first, then your listings, then another ad.

    Have fun!!!
  6. Lhotch curmudgeon


    just use .iteration instead of .index
  7. seymourjames All Hands On Deck

    You have to do a bit more than that Mike or you get problems with searchresults.php because google adsense cannot respond quickly enough to make good matching ads. Perhaps over time it can but in general searchresults should be excluded from being indexed anyway (their advice) via robots.txt. There is also the issue of the last page if it is not a full page of property ads. Best to put the code outside of the loop for that. Likewise no code in the foreachelse for the same reason as search results. It seems to make weird ads otherwise that are not about property in France (my target market) t or atleast it did not work well for me. I have adsense in the footer area anyway. For example,

    The last page of properties in France for the area of Dordogne
    Property Dordogne

    A full page of French property in the same area
    Property Dordogne 34

    Here is the basic code I used because I have 8 listings of french properties and want it always show adsense after 4 listings and also at the end, if less than 4 properties, just at the end. In my case templatecodes provides a nice way to to test and exclude pages of search results because we malke all the script names available for SEO purposes amongst other reasons (the if test for search results)..

    {foreach from=$results item="entry" name=foo}

    {if $script_name <> "searchresults.php"}

    {if $smarty.foreach.foo.index == 4}
    <tr>
    <td colspan="4">
    <p align="left">
    <script type="text/javascript"><!--
    google_ad_client = "pub-xxxxxxxxx";
    /* 728x90, created 23/03/11 */
    google_ad_slot = "4485416383";
    google_ad_width = 728;
    google_ad_height = 90;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    </p>
    </td>
    </tr>
    {/if}
    {/if}

    <tr> .....

    {/foreach}
    {if $script_name <> "searchresults.php"}
    <tr>
    <td colspan="4">
    <p align="left">
    <script type="text/javascript"><!--
    google_ad_client = "pub-xxxxxx";
    /* 728x90, created 23/03/11 */
    google_ad_slot = "4485416383";
    google_ad_width = 728;
    google_ad_height = 90;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    </p>
    </td>
    </tr>
    {/if}
    </table>

    P.S Larry - yes, you being the SMARTY man for sure - that works too. Makes it even simpler.
  8. nachtwerkmir Member

    Strange, i tried both ways (Mik-N-Tosh's and Seymour James), but nothing happens. No adsense shows up in the listing. Does this still work with the latest version?

Share This Page