问题
I'm trying to display an advertisement every after 3 posts in a wordpress blog. Could you guys check something that's wrong in the code?
See the code here
回答1:
see Make $after_every = 0 and add $after_every++ bottom of while loop
then add one condition
if($after_every%3==0){ Show add}
I think it works.
回答2:
I can't figure out why are you using modulus there. http://php.net/manual/en/language.operators.arithmetic.php
I think that is something you didn't want. The way I usualy do this is:
if( $ad_counter >= 3 ) {
$ad_counter = 0;
echo '<h2 style="color:red;">Advertisement or custom content here</h2>';
}
And you can remove line 12 :)
来源:https://stackoverflow.com/questions/6771813/display-ad-every-after-3-posts