Know how to place adsense in your favourite posts in wordpress

Discussion in 'Placement / Reviews / Examples' started by dexterwizard4, Dec 16, 2008.

  1. #1
    in the page where you want put this like page.php or archieves .php

    you could see a line at the beginning like


    ?php if (have_posts()) : ?>
    or
    ?php while (have_posts()) : ?>
    
    PHP:
    add the code below before that

    <?php $adcount = 1; ?>
    PHP:
    so that it will look like

    <?php $adcount = 1; ?>
    
    ?php if (have_posts()) : ?>
    PHP:
    now find the position where you want put the ads like below title above title

    etc and paste the code as shown below

    <?php if ($adcount == 1||$adcount == 5||$adcount == 9) : ?>
    
    <script type="text/javascript"><!--
    google_ad_client = "pub-";
    /* 300x250, created 11/11/08 */
    google_ad_slot = "4618539363";
    google_ad_width = 300;
    google_ad_height = 250;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    <?php endif; $adcount++; ?>
    PHP:
    note:in this you could change the post where you want the ads to appear,by changing
    the variable' $adcount == 1', in 'if 'condition ,if u need only one ad then delete

    the varibale after the '||'sign ie
    <?php if ($adcount == 1) : ?>
    PHP:
    if the code is made as shown above,it gives only one ad in first post like that
    if you want three ads in adjacent posts
    <?php if ($adcount == 1||$adcount == 3||$adcount == 5) : ?>
    PHP:
    like that since the increment goes by 2...
    if you want it on alternative posts paste as in the script mentioned

    then go below the page where it ends look for this piece of script

    <?php endwhile; ?>
    PHP:
    paste the code below before that
    <?php $adcount++; ?>
    PHP:
    so it will look like below
    <?php $adcount++; ?>
    <?php endwhile; ?>
    PHP:
    thats all
    demo site:http://electricalandelectronics.org/?cat=343
     
    dexterwizard4, Dec 16, 2008 IP
  2. SEOBOT

    SEOBOT Banned

    Messages:
    794
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    How many ads do you want to display in fav post?
     
    SEOBOT, Dec 16, 2008 IP
  3. psdealer

    psdealer Active Member

    Messages:
    116
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Interesting method,thanks!
     
    psdealer, Jan 2, 2009 IP
  4. zedomax

    zedomax Peon

    Messages:
    212
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    zedomax, Jan 2, 2009 IP