Display Ad every after 3 Posts olatechproFebruary 18, 20231 Views 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 Post Views: 1 Related postsGet rid of this Strict Standards warningWooCommerce: get_current_screen not working with multi languageCan’t login on WordPressForce HTTPS using .htaccess – stuck in redirect loopWordPress: Ajax not working to insert, query and result dataHow Can I pass an image file to wp_handle_upload?
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. Log in to Reply
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 🙂 Log in to Reply
see Make $after_every = 0 and add $after_every++ bottom of while loop
then add one condition
I think it works.
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:
And you can remove line 12 🙂