Ads between posts in homepage (2 posts)

  1. masmasmous
    Posted 5 years ago #

    i need to add an ad between the 3d and 4th post experts in my home page

    <?php while (have_posts()) : the_post(); ?>
    					<!-- Start: Post -->
    					<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    						<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    						<p class="postmeta">Posted on <a href="<?php the_permalink() ?>"><?php the_time('F jS, Y') ?></a> by <?php the_author() ?></p>
    						<div class="entryContent">
    						    <?php the_post_thumbnail(); ?>
    							<?php the_excerpt(); ?>
    						<p>Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?> </p>
    					<div class="clear"></div>
    					<!-- End: Post -->
    				<?php endwhile; ?>

    is there a way to do this

  2. Michael
    Forum Moderator
    Posted 5 years ago #

    one possible way is to use a counter variable and increment/check it within the loop:

    <?php while (have_posts()) : $counter = 0; the_post(); ?>

    <?php $counter++; if($counter == 3) { /*show ad*/; }; endwhile; ?>

    (untested; only the edited lines shown)

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.