WordPress.org

Ready to get started?Download WordPress

Forums

Chun
Adding ads between posts on the homepage (3 posts)

  1. el terrible bmw
    Member
    Posted 9 months ago #

    How would I add adsense in between first and second posts on the homepage?

    Thanks

  2. Laura Hartwig
    Member
    Posted 9 months ago #

    There are several ad plugins that allow you to do things like this. Have you looked into them? This is one I like to use: http://wordpress.org/plugins/adrotate/, but there are several others that also allow ads to be placed within posts.

    Otherwise you will have to modify the php code for your homepage.

  3. el terrible bmw
    Member
    Posted 9 months ago #

    I just changed index.php and added some code. Here it is if anyone cares.

    <?php if ( have_posts() ) : ?>
    
    <?php $count = 1; ?>
    
    	<?php while ( have_posts() ) : the_post(); ?>
    
    		<?php get_template_part( 'content', ( post_type_supports( get_post_type(), 'post-formats' ) ? get_post_format() : get_post_type() ) ); ?>
    
    		<?php if ( is_singular() ) comments_template(); // Loads the comments.php template. ?>
    
    		<?php if($count == 1):?>
    
                <div class="ad-homepage">
    		  // Ad code goes here
                </div>
    
            <?php endif;?>
    
    	<?php $count++;?>
    
    	<?php endwhile; ?>
    
    <?php else : ?>
    
    	<?php get_template_part( 'loop-error' ); // Loads the loop-error.php template. ?>
    
    <?php endif; ?>

Reply

You must log in to post.

About this Theme

About this Topic

Tags

No tags yet.