• Resolved gerardog2000

    (@gerardog2000)


    I know that this question has been asked many times before and actually once by myself. The reason that I am asking it again is because my current theme does not run the typical index.php. This link is the link to the question that I posted 1 year ago.

    https://www.ads-software.com/support/topic/inserting-ads-between-every-5th-post?replies=5

    And this is the link to my current themes index.php code.

    https://pastebin.com/EixLARgq

    As you can see, this is not the typical loop. I followed the instructions that I received for my other theme but I am confused as to where to insert the code in this theme because the index is in a different configuration. I would be ever so greatful if somebody can guide me in the right direction.

    I apologize if this exact question has been asked before but I could not find it in this scenario.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Try looking in post.php or post-homepage.php (if that file exists).

    Thread Starter gerardog2000

    (@gerardog2000)

    I looked at post.php but I do not see the <?php endwhile; ?> code. I do not see anything in the post.php page that stands out. The index.php page does have the following code though.

    <?php
                    if (have_posts()) : while (have_posts()) : the_post();
    get_template_part('post', 'homepage');
                    endwhile;
                    else :
                        get_template_part('post', 'noresults');
                    endif;
                    get_template_part('navigation');?>

    Drop a copy of post.php into the WordPress pastebin and post the pastebin url here. Perhaps someone will be able to suggest a solution.

    Thread Starter gerardog2000

    (@gerardog2000)

    here is the link to pastebin.

    https://pastebin.com/QCKEQde4

    Just to clarify some more. I am looking to insert ads into my homepage after every few posts. Lets use after every 4th post for an example. Thanks again for the help.

    Ah! Now I understand. Try replacing:

    <?php
    if (have_posts()) : while (have_posts()) : the_post();
    get_template_part('post', 'homepage');
    endwhile;

    with:

    <?php
    if (have_posts()) : $c = 0; while (have_posts()) : the_post();
    $c ++;
    get_template_part('post', 'homepage');
    if ($c > 2 ) {
    	$c = 0;?>
    	[ insert ad code here ]
    	<?php
    }
    endwhile;

    in index.php.

    Thread Starter gerardog2000

    (@gerardog2000)

    Thanks that worked like a charm. If I want to do the same when somebody clicks on a category and it is listing a list of posts I would add the same code into either Single.php or page.php?

    when somebody clicks on a category and it is listing a list of posts

    that would possibly be archive.php or category.php;

    see https://codex.www.ads-software.com/Template_Hierarchy

    Thread Starter gerardog2000

    (@gerardog2000)

    Cool. Everything works great. Thanks again.

    Right on, esmi. That’s the only code I could get to work with Twenty Twelve because of its odd php tag placements.

    The only problem I had was that I wanted more than one ad, and when I tried that, it placed ads with every post, and I ended up with yellowish ad place holders after the 3 max (Google AdSense).

    display:none had no effect on the ids, and placing the code inside divs and trying to collapse them did not work either (besides, I did not know if having theme there was violating Google’s TOU.

    Finally the Ad Injection plugin came to my rescue.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Adding ads in between posts’ is closed to new replies.