How do I add Google Adsense every x posts?

浪尽此生 提交于 2019-12-04 18:22:14

Use {block:Post6} and {block:Post12} to show content on the 6th and 12th posts. Documentation here

Example usage:

{block:Posts}
    {block:Photo}Your content blocks here{/block:Photo}
    {block:Video}Your content blocks here{/block:Video}

    {block:Post6} Your ad code here{/block:Post6}
    {block:Post12}Your ad code here{/block:Post12}
{/block:Posts}
Artoni

Add this

{block:Post6} Your ad code here{/block:Post6}
{block:Post12}Your ad code here{/block:Post12}

above {/block:Posts} to add ads.

I found the solution and the ads look great, and have their own photo-border, adding to the look of the blog. I used bfred's method and placed the ad code right before

{/block:Posts} 

However, even though the ads were being loaded after posts 6 and 12, they were inside those posts, sharing the same photo-border, and that didn't add up to the look of the whole theme. So I looked for the line of code that was causing the photos to be organised and have their own space on the grid. In my case this was the line:

<article id="{PostID}" class="entry{block:HasTags}
{block:Tags} tag-{Tag}{/block:Tags}
{/block:HasTags}{block:Photo} photo-border{/block:Photo}">

Once I found it, after trying different placements, I finally placed this line inside

{block:Post6} {/block:Post6}

I also had to change the size of the ads so that the width could match the width of the photo-posts on my blog. So the final code looks like this:

{block:Post6}

<article id="{PostID}" class="entry{block:HasTags}
{block:Tags} tag-{Tag}{/block:Tags}    
{/block:HasTags}{block:Photo} photo-border{/block:Photo}">

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- page -->
<ins class="adsbygoogle"
 style="display:inline-block;width:264px;height:250px"
 data-ad-client="ca-pub-7147439154267017"
 data-ad-slot="1006289886"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

</article>

{/block:Post6}


{block:Post12}

<article id="{PostID}" class="entry{block:HasTags}
{block:Tags} tag-{Tag}{/block:Tags}     
{/block:HasTags}{block:Photo} photo-border{/block:Photo}">

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- page -->
<ins class="adsbygoogle"
 style="display:inline-block;width:264px;height:250px"
 data-ad-client="ca-pub-7147439154267017"
 data-ad-slot="1006289886"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>


</article>

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