WordPress.org

Ready to get started?Download WordPress

Forums

How to put adsense after first topic? (9 posts)

  1. james2002
    Member
    Posted 7 years ago #

    I don't know how to put adsense on my newly created blog about green tea. My blog is as follows:

    http://egcg.co.uk/greentea/

    I will appreciate if someone show me how to put adsense after first topic as well as on right column.

    thank you

  2. onocrotalus
    Member
    Posted 7 years ago #

    Consider using one of the available adsense-related plugins to do this.

  3. mutube
    Member
    Posted 7 years ago #

    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.

  4. warning
    Member
    Posted 7 years ago #

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

  5. davidchait
    Member
    Posted 7 years ago #

    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

  6. Chris_K
    Member
    Posted 7 years ago #

    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.

  7. warning
    Member
    Posted 7 years ago #

    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?

  8. rudolf45
    Member
    Posted 7 years ago #

  9. warning
    Member
    Posted 7 years ago #

    thanks for that

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.