WordPress.org

Support

Support » Installation » How to put adsense after first topic?

How to put adsense after first topic?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Consider using one of the available adsense-related plugins to do this.

    james2002: To add code after the first post (in a loop) use something like this:

    Before the loop do:

    $postcount=0;

    Then inside the loop (after the post) put your code e.g.

    <?php
    $postcount++;
    if($postcount==1){?>
    <div><!--adsense--></div>
    <?php } ?>

    This will count up posts and only display the ad after the first one (i.e. when $postcount is equal to 1). Obviously you’ll need to replace <!–adsense–> with either the code from Google or the plugin function to display an Ad.

    You can do even, odd, every 3rd etc. by changing the condition on the if statement.

    As the previous poster said some of this can be simplified by using one of the Adsense plugins. If you are using Widgets Adsense Manager (my own plugin) will allow you to drag and drop Ads around the sidebars.

    If you need any more help let me know.

    Where do you find the bulk of the php code? Where’s the segment of the loop you showed found?

    I haven’t tried my CG-Inbetween plugin with the latest releases in a while, but it was designed to handle this sort of thing — so long as you can insert one function call in PHP into the right place in the theme. 😉

    Usually the theme’s index.php file is where the main loop is, and the outputting of each post’s individual data.

    -d

    Where do you find the bulk of the php code? Where’s the segment of the loop you showed found?

    Peek in your current theme’s index.php file.

    Read up on The_Loop.

    Ok, I found the loop in the index.php, and placed the following in there (bold):

    <div id=”content” class=”narrowcolumn”>
    <?php $postcount=0; ?>
    <?php if (have_posts()) : ?>

    <?php while (have_posts()) : the_post(); if($postcount++ ==1){ ?>
    <b>Test worked</b>
    <$php } ?>

    But it didn’t work?

    thanks for that

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to put adsense after first topic?’ is closed to new replies.
Skip to toolbar