gerardog2000
Member
Posted 10 months ago #
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.
http://wordpress.org/support/topic/inserting-ads-between-every-5th-post?replies=5
And this is the link to my current themes index.php code.
http://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.
Try looking in post.php or post-homepage.php (if that file exists).
gerardog2000
Member
Posted 10 months ago #
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.
gerardog2000
Member
Posted 10 months ago #
here is the link to pastebin.
http://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.
gerardog2000
Member
Posted 10 months ago #
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 http://codex.wordpress.org/Template_Hierarchy
gerardog2000
Member
Posted 10 months ago #
Cool. Everything works great. Thanks again.