问题
I found this example http://wearevanity.co where the new ads are loaded in every page.
In addition to the maximum number of posts allowed by Tumblr
. The ads are automatically adjusted to the layout of the page, which makes them add to the look of the blog.
Does anyone know how to achieve this? If so, would you please explain it to us, step by step?
回答1:
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}
回答2:
Add this
{block:Post6} Your ad code here{/block:Post6}
{block:Post12}Your ad code here{/block:Post12}
above {/block:Posts}
to add ads.
回答3:
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}
来源:https://stackoverflow.com/questions/24222941/how-do-i-add-google-adsense-every-x-posts