Okay
  Public Ticket #196982
Ad Every 3rd Post in the Loop
Closed

Comments

  • Brad started the conversation

    How could I add my ad code after every 3rd blog post? I am trying to do this on the home page blog with masonry activated.

    Example posted...

    I just need the code to add to the loop and the code to make sure it fits in with Masonry (assuming it's just a class added to the div), the rest I can style on my own.

  •  1,070
    ThemeNectar replied

    Hey Brad, sorry for the delay - this ticket was flagged by the support staff for my attention since it's a mod request.

    From what i'm getting from the screenshot I think there's a much easier way to go about this. I would recommend simply using the masonry layout with sidebar and then filling up your sidebar widgets with ads - it effectively would work exactly the same. If you were concerned about the ads appearing on other pages that might use the sidebar as well you can sort that out with this plugin http://wordpress.org/plugins/widget-logic/

    Please let me know if there's any reason this won't work or why you didn't opt for this method before thinking of the mod you requested.

    Cheers :)

  • Brad replied

    It's all good. The reason why I was asking is, I would love to spread the ads out. Not have them all bunched up in the sidebar. I would like the sidebar to hold useful info as well.

    Basically I'm pretty confident I can get masonry to work with the ads, so all I really need is the code that would integrate into the loop and to post the ad every 3 articles.

    I've tried to use some of the methods shown here (same principle):

    http://wordpress.org/support/topic/adding-a-clearing-div-to-every-third-post-in-the-loop

    and here:

    http://wordpress.org/support/topic/inserting-ads-between-every-5th-post

    they don't generally play well with Salient's loop (as in it kills the page).



  •  1,070
    ThemeNectar replied

    Hey again! Hope you had a good Easter :)

    the methods listed in your URLs are indeed the way you would go about that - (checking if the current loop count is divisible by 3). Just make sure you're defining the $count variable right before to the loop to equal 0 and then adding $count++ into the bottom of the loop so that it can properly increment. Also the correct place to do this mod is going to be at the nectar_blog_processing function in the shortcode-processing.php file located in the nectar/tinymce directory :)

    Cheers

  • Brad replied

    Alright. I know I didn't get to this until now, but I have been working on this and nothing I post in the shortcode-processing.php file in the nectar_blog_processing function shows up.

    Here is the code I am using...

    $postnum = 0;

    if(have_posts()) : while(have_posts()) : the_post(); ?>

    <?php
    global $more;
    $more = 0;
    if ( floatval(get_bloginfo('version')) < "3.6" ) {
    //old post formats before they got built into the core
    get_template_part( 'includes/post-templates-pre-3-6/entry', get_post_format() )

    } else {

    //WP 3.6+ post formats
    get_template_part( 'includes/post-templates/entry', get_post_format() );
    } ?>

    <?php $postnum++; if($postnum%4 == 0) { ?>
    My Ad Code would go here
    <?php } ?>

    <?php endwhile; endif; ?>

  •  1,070
    ThemeNectar replied

    Hey again!

    If you're not using a blog element inside of Visual Composer or through a nectar shortcode and are instead using actual posts page as defined in settings > reading - you'd need to make the mod in the index.php file :)

  • Brad replied

    This maybe overstepping my bounds, and if it is I apologize. The last piece to the Masonry Google Ads puzzle is how do I infuse the added ad units into the masonry wall.

    Again, if this is asking too much I apologize.

    Thanks for all your help.

  • Brad replied

    Also, I already added the masonry classes to the ad code. 

    Here is what I have:

    <div class="post ad masonry-blog-item isotope-item">

    <div id='div-gpt-ad-numbers' style='width:300px; height:250px;'>

    <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1406997094655-3'); });</script>

    </div>

    </div>

  •  1,070
    ThemeNectar replied

    Hey again,

    Anyway I could check the page out live now? I tried to inspect it live at

    http://www.hammerandnigel.com/ but it seems you may have moved the site

    Cheers


  • Brad replied

    I just switched it to the Shortcode-processing.php because I decided to customize the homepage.

    The Ad code is now in place again and it appears that sometimes it loads correctly, other times it does not.

    Is it because google DFP most likely loads after the content is in place?

  • Brad replied

    Attached shows the ads over the content. Granted, only one ad loaded (that is step 2 I need to take care of and think I have a work around for that.... it is a Google DFP instance issue).

  •  1,070
    ThemeNectar replied

    I overlooked in your last code snippet paste that you were using a div instead of an article - change your code to this:

    <article class="post ad masonry-blog-item isotope-item">
    
    <div id='div-gpt-ad-numbers' style='width:300px; height:250px;'>
    
    <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1406997094655-3'); });</script>
    
    </div>
    
    </article>
    
    
    
  • Brad replied

    Perfect. Fixed it. I didn't even think about it.