• Hi I’m having trouble adding my ads in between my posts. I’m using the adventure theme and would like the ad to repeat every 4th post. I read the other how to but couldn’t find one with the same code as mine, so I chickened out. My knowledge is limited. Can anyone help me out and let me know what I need to change to make it so my iframe (below) shows up every 4th post. my site is NSFW twitmytwat.com

    <?php if(!$show_ads){ ?>
    <iframe allowtransparency="1" frameborder="0" height="124" id="plwpr5437750295eb5ecde11.86705177" scrolling="no" src="http://widget.plugrush.com/twitmytwat.com/xdz" width="499"></iframe>
    <?php $show_ads = 1; } ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter twitmytwat

    (@twitmytwat)

    forgot to mention I got it right now that the ad is under the first post.

    I would simply implement a php loop counter.

    Create a function to put in functions.php that is going to output the html for the ad.

    function tiny_twat_ads() { ?>
    
      <iframe allowtransparency="1" frameborder="0" height="124" id="plwpr5437750295eb5ecde11.86705177" scrolling="no" src="http://widget.plugrush.com/twitmytwat.com/xdz" width="499"></iframe>
    
    <?php }

    Now go into your template, index.php and find the loop and define a variable to hold the count and add this before the loop starts.

    <?php $count = 0; ?>
    
    <?php if ( have_posts() ) : while ( have_posts() ) : the_posts();  ?>
         $count++;  //this increases the integer value of our count every time the loop runs
          if ( 0 == $count % 4 )  //modulus php operator returns the remainder of division so every 4th post this will return true
                tiny_twat_ads();
    
            // continue with loopy stuff
    Thread Starter twitmytwat

    (@twitmytwat)

    this is what my index.php looks like, where should it go?

    <?php
    /**
     * @package WordPress
     * @subpackage Adventure_Journal
     */
    
    get_header(); ?>
    
    <div class="content type-category" <?php ctx_aj_getlayout(); ?>>
      <div id="col-main" style="<?php echo ctx_aj_customwidth('content'); ?>">
        <div id="main-content" <?php ctx_aj_crinkled_paper(); ?>>
            <!-- BEGIN Main Content-->
            <h1><?php echo '<span>'.single_cat_title('',false).'</span>';?></h1>
            <?php
                $category_description = category_description();
                if ( ! empty( $category_description ) )
                        echo '<div class="archive-meta">' . $category_description . '</div>';
    
                /* Run the loop for the category page to output the posts.
                 * If you want to overload this in a child theme then include a file
                 * called loop-category.php and that will be used instead.
                 */
                get_template_part( 'loop', 'category' );
            ?>
          <!-- END Main Content-->
        </div>
      </div>
      <?php get_sidebar(); ?>
      <div class="clear"></div>
    </div>
    <?php get_footer(); ?>

    Your loop is in the template loop-category.php

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[NSFW] adding ads in between posts’ is closed to new replies.