• Hello,

    I have been searching for a way to display ads in my homepage. my homepage have 20 posts. and i want to show an ad just after 10th post. i got a code to add ads after every 10th post, but i only want to show an ad after the 10th post. don’t want to repeat it.

    can someone help me on this?

    thanks
    Saeed

Viewing 5 replies - 1 through 5 (of 5 total)
  • i got a code to add ads after every 10th post,

    please post that code – it might be easier to adapt that code than to suggest a new one.

    Thread Starter Madalin_JFT

    (@wpbox)

    @alchymyth, here is the code that i currently use (basic outline):

    <?php $counter =0; ?>
    	<?php if ( have_posts() ) : ?>
    		<?php while ( have_posts() ) : the_post(); $count++; ?>
    			<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    			<?php the_title(); ?>
    			<?php the_excerpt(); ?>
    			</div>
    			<?php $postnum++; if($postnum%10 == 0) { ?>
    			<div>AD CODE HERE</div>
    			<?php } ?>
    		<?php endwhile; ?>
    			<?php wp_pagination(); ?>
    		<?php else : ?>
    			<?php get_template_part( 'no-results', 'index' ); ?>
    		<?php endif; ?>

    thanks!

    this is the current conditions to show the ad after every 10 posts:

    if($postnum%10 == 0)

    change it to have just after 10 posts:

    if($postnum == 10)

    Thread Starter Madalin_JFT

    (@wpbox)

    wow! that simple? i wasted couple of days searching the web for that piece of code, i should have asked here first, my bad!

    thank you alchymyth for your quick responses.

    In Which File should i put the code. Please explain little in details as i am a fresher to WP and PHP.

    Thanks In Advacne

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to display an ad after a number of post in homepage?’ is closed to new replies.