Skip to main content
How to add an Adsence block between articles list in Drupal 7

When monetizing a site, it's sometimes a challenge to display some ad units on the home page, or category page between the article announcements. If the list of articles on your site is not displayed through Views, but through default announcements, then to solve this we need to insert the following php code in the theme template file node.tpl.php:

<?php if ( !$page && ($id == 2 || $id == 4)) : ?>adsense code goes here <?php endif; ?>

where 2 and 4 id of articles after which it is necessary to output advertising block. After which article the output of course is up to you, and this can be easily changed by replacing 2 and 4 with the numbers you want, and if two blocks are not enough - add more, for example:

<?php if ( !$page && ($id == 2 || $id == 4 || $id == 8 || $id == 10)) : ?>adsense code goes here <?php endif; ?>


About The Author

Author of this blog. In SEO for over 10 years. In addition to SEO, I am interested in everything related to technology and earnings on the Internet, which I try to share with readers.