Display Ad every after 3 Posts

余生长醉 提交于 2019-12-12 21:25:36

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!