WordPress.org

Ready to get started?Download WordPress

Forums

Ads between posts in homepage (2 posts)

  1. masmasmous
    Member
    Posted 3 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(); ?>
    						</div>
    						<p>Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?> </p>
    					</div>
    					<div class="clear"></div>
    					<!-- End: Post -->
    				<?php endwhile; ?>

    is there a way to do this

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 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

Tags

No tags yet.