• Resolved thebookreporter

    (@thebookreporter)


    I’ve been trying to insert a blogads ad after the first post on my twenty eleven theme without luck (my site is here: https://newbooksinbrief.com/). My loop in my index.php is as follows:

    <?php if ( have_posts() ) : ?>
    
    				<?php twentyeleven_content_nav( 'nav-above' ); ?>
    
    				<?php /* Start the Loop */ ?>
    				<?php while ( have_posts() ) : the_post(); ?>
    
    					<?php get_template_part( 'content', get_post_format() ); ?>
    
    				<?php endwhile; ?>
    
    				<?php twentyeleven_content_nav( 'nav-below' ); ?>
    
    			<?php else : ?>

    Any suggestions?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Do not edit the Twenty Eleven theme. First create a child theme for your changes.

    Thread Starter thebookreporter

    (@thebookreporter)

    Thank you for your response. I do have a child theme that I could make the changes on.

    In your child theme’s copy of index.php, try replacing:

    <?php while ( have_posts() ) : the_post(); ?>
    <?php get_template_part( 'content', get_post_format() ); ?>
    <?php endwhile; ?>

    with:

    <?php $c= 0;while ( have_posts() ) : the_post(); $c++;?>
    <?php get_template_part( 'content', get_post_format() ); ?>
    <?php if( $c == 1 && !is_paged() ) :?>
    [ Ad code goes here ]
    <?php endif;>
    <?php endwhile; ?>

    before the line with the endwhile; add for example:

    <?php if( $wp_query->current_post == 0 ) { ?>
    YOUR AD CODE
    <?php } ?>
    Thread Starter thebookreporter

    (@thebookreporter)

    Thank you both for your suggestions. However, I’m afraid neither worked. I’m not sure if this will help but my ad code is as follows:

    <script language="javascript" src="https://cache.blogads.com/935376472/feed.js"></script>

    Place the following code before <?php endwhile; ?>

    <?php if(!$show_ads){ ?>
    Insert Code Here
    <?php $show_ads = 1; } ?>
    Thread Starter thebookreporter

    (@thebookreporter)

    Thanks marviepons, but I’m afraid that didn’t work either.

    does your code work if you just add it into index.php (forget about the conditional statements right now)?

    did you leave the code in your site for somebody tho check the output?

    Thread Starter thebookreporter

    (@thebookreporter)

    O.k. I’ve just added the code into my index.php (just before <?php endwhile; ?>) and I’ll leave it there for now. I’ve added other ad codes onto my site in other places, and they always show up as ‘advertise here’ on the site. You can see this text just beneath the banner ad beneath the header and beneath the poster ad near the top of the sidebar.

    Thread Starter thebookreporter

    (@thebookreporter)

    O.k. wait. alchymth, I’ve just tried your solution with a different ad code and it is working, so it appears there’s something wrong with the ad code I was using. Thank you for the solution. I’ll have to contact my ad company and ask them to fix the code. Thanks again for your patience.

    Thread Starter thebookreporter

    (@thebookreporter)

    Thanks all.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘How to insert an advertisement after first post’ is closed to new replies.