WordPress.org

Ready to get started?Download WordPress

Forums

how to add adsence code after every post in home page (12 posts)

  1. yashmistrey
    Member
    Posted 2 years ago #

    i want to put ad code after every 3rd post in my home page
    how to do that

    i am using this code right now

    <?php if ($count==3) { ?>
     <div class="clear"> </div>
    <?php dt_show_ads('position=Archives&before=<div class="adzone_b">&after=</div>&title=्&#2334');?>
    		<div class="clear"> </div>
    <?php } ?>
    <?php $count = $count + 0; ?>

    but it display ad after 2nd post

  2. Digital Raindrops
    Member
    Posted 2 years ago #

    You are limited to three Google Adsense adbolcks per page, so if you have the default 10 posts per page, and no Adsense in the sidebar.

    Try after if have posts.
    <?php $count=1; ?>

    Then inside the loop (while have posts)

    <?php if (!$count % 3 && $count < 10 ) : ?>
     <div class="clear"> </div>
    <?php dt_show_ads('position=Archives&before=<div class="adzone_b">&after=</div>&title=्&#2334');?>
    		<div class="clear"> </div>
    <?php endif; ?>
    <?php $count++; ?>

    HTH

    David

  3. yashmistrey
    Member
    Posted 2 years ago #

    thanks for reply

    not working, i am confused, please help
    i have paste my code here please if can look at this http://pastebin.com/PwWKJ5Jm

  4. Digital Raindrops
    Member
    Posted 2 years ago #

    Not tested but checked and adjusted.

    http://pastebin.com/kg263Kua

    HTH

    David

  5. yashmistrey
    Member
    Posted 2 years ago #

    thanks David
    i am giving you the test url

    here is the cache of that page http://goo.gl/UuzyC

    you'll see the 468*60 ad showing after 2 post i
    want to show after every 4 post

    i upload your code & it showing error:
    Parse error: syntax error, unexpected T_ENDIF in E:\HostingSpaces\shreshth\News.shreshthbharat.in\wwwroot\wp-content\themes\BharatNews\archive-default.php on line 34

  6. Digital Raindrops
    Member
    Posted 2 years ago #

    Looking at the page layout you need the ads after posts 3. 9 and 15

    (latest)
    [ 01 ]
    [02] - [03]
    [ adBlock ]
    [04] - [05]
    [06] - [07]
    [07] - [09]
    [ adBlock ]
    [10] - [11]
    [12] - [13]
    [14] - [15]
    [ adBlock ]

    Again: Un-Tested Code
    http://pastebin.com/erYY79mq

    HTH

    David

  7. yashmistrey
    Member
    Posted 2 years ago #

    yes and
    i check again it showing error
    http://goo.gl/fO9Oi
    please have a look this arrow indicating code
    https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-snc6/226114_234354489935415_213203208717210_629927_7818150_n.jpg

  8. Digital Raindrops
    Member
    Posted 2 years ago #

    Ok,
    Found it a few lines above, third time lucky!.

    Try http://pastebin.com/xsSMgWK4

    HTH

    David

  9. yashmistrey
    Member
    Posted 2 years ago #

    error indicating this line - 57 <?php if ( $count == 3 $count == 9 || $count == 15 ) : ?> line http://goo.gl/BilW6

  10. Digital Raindrops
    Member
    Posted 2 years ago #

    <?php if ( $count == 3 $count == 9 || $count == 15 ) : ?>

    Should be:
    <?php if ( $count == 3 || $count == 9 || $count == 15 ) : ?>

    David

  11. yashmistrey
    Member
    Posted 2 years ago #


  12. yashmistrey
    Member
    Posted 2 years ago #

    thanks David ! finally it working now, thanks a lot for your great support
    it's done i knew it , thanks

    is there any conditional way to change ad ?

    like

    $count == 3 - [ show_ads - 1 ] if i need different ad on this zone
    $count == 7 - [ show_ads - 2 ] if i need different ad on this zone
    $count == 10 -[ show_ads - 3 ] if i need different ad on this zone

    <?php if ( $count == 3 || $count == 7 || $count == 10 ) : ?>

Topic Closed

This topic has been closed to new replies.

About this Topic