insert ads between mysql results blog posts in wordpress

i have the code:

<?php
global $post;
$args = array( 'numberposts' => 24, 'order' => 'ASC', 'category' => 9 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) :  setup_postdata($post); ?>
<div id="lajme-bllok-item-vogel">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('lajmet-thumb'); ?></a>
<div id="lajme-bllok-item-title-vogel"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<div id="top-news-title-linku-posht"><?php for( $i=1; $i<=4; $i++){ $prop_det_url = get_field('link'.$i); if( $prop_det_url != '' ){ ?>
<li><a href="<?php echo $prop_det_url; ?>" target="_blank"><?php the_field('link_titull'.$i); ?></a></li> <?php } } ?></div></div></div>
<div id="social-media-vogel"><?php if ( function_exists( 'ADDTOANY_SHARE_SAVE_KIT' ) ) { ADDTOANY_SHARE_SAVE_KIT(); } ?></div>
<?php endforeach; ?>

How can i add exmpel: iframe code after the first result from database and then continue with second post third etc like a blog?

Read More

Thank you. in advance

Related posts

Leave a Reply

1 comment

  1. I believe this is what you need to do

    <?php
    global $post;
    $ctr = 1;
    $args = array( 'numberposts' => 24, 'order' => 'ASC', 'category' => 9 );
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) :  setup_postdata($post); ?>
        <div id="lajme-bllok-item-vogel">
            <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('lajmet-thumb'); ?></a>
            <div id="lajme-bllok-item-title-vogel"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            <div id="top-news-title-linku-posht"><?php for( $i=1; $i<=4; $i++){ $prop_det_url = get_field('link'.$i); if( $prop_det_url != '' ){ ?>
            <li><a href="<?php echo $prop_det_url; ?>" target="_blank"><?php the_field('link_titull'.$i); ?></a></li> <?php } } ?></div></div>
        </div>
        <div id="social-media-vogel"><?php if ( function_exists( 'ADDTOANY_SHARE_SAVE_KIT' ) ) { ADDTOANY_SHARE_SAVE_KIT(); } ?></div>
        <?php if ($ctr == 1) : ?>
            // Your ad/iframe here
        <?php endif; ?>
        <?php $ctr++; ?>
    <?php endforeach; ?>