WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How add 2 adsense (below the first and second post) in main page or category? (4 posts)

  1. Erfo
    Member
    Posted 4 years ago #

    Hi.
    I want to add 2 google ads in main page or in category: one adsense below the first post and one adsense below the second post.

    I use this code:
    <?php $count = 1; ?> /* before <?php if (have_posts())... */
    and after this

    <?php if ($count == 1) : ?>
    code adsense
    <?php endif; $count++; ?>

    and so, I have a adsense below the first post, but I want also another adsense below the second post.

    How?
    Thanks

  2. Erfo
    Member
    Posted 4 years ago #

    Sorry,
    I found the solution.

    Before this: <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    I put this:

    <?php
    $postnum = 1;
    $showadsense1 = 1;
    $showadsense2 = 2;
    ?>

    Before this:<?php endwhile; else: ?>
    I put this:

    <?php if ($postnum == $showadsense1) {
    echo '
    code adsense
    ';
    } ?>
    
    <?php if ($postnum == $showadsense2) {
    echo '
    code adsense
    ';
    } ?>
    <?php $postnum++; ?>
  3. WPContent.com
    Member
    Posted 4 years ago #

    Hi Erfo,

    I posted a video tutorial on how to do this. The video can be found here: http://www.wpcontent.com/post/190.

    I hope that helps,
    Eric

  4. ishan001
    Member
    Posted 3 years ago #

    Works like a charm! Thanks a lot.

Topic Closed

This topic has been closed to new replies.

About this Topic