I have a view that output the content nodes as grid. (instigram style). How to insert an advertisement block in a random location within the views list.
Node Node . . Advertisement . . Node Node
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI have a view that output the content nodes as grid. (instigram style). How to insert an advertisement block in a random location within the views list.
Node Node . . Advertisement . . Node Node
You can override the format specific template like views-view-unformatted.tpl.php
(you can find the right file based on your requirement) and then use some custom code like
<?php if (($id % 2) == 0): ?>
Do what-ever you want to do here.
<?php endif; ?>
This module hosted on github https://github.com/pedroposada/custom_views_nthrow seems to do the same more modularly.
Instructions : http://www.pedroposada.com/blog/insert-whatever-every-nth-row-views.html-0
If you want to have your custom code after first row then override your default views-view-unformatted.tpl.php with this code:
<?php if (!empty($title)): ?>
<h3><?php print $title; ?></h3>
<?php endif; ?>
<?php foreach ($rows as $id => $row): ?>
<div<?php if ($classes_array[$id]) { print ' class="' . $classes_array[$id] .'"'; } ?>>
<?php print $row; ?>
</div>
<?php if ($id == 0 || $id == 5): ?>
Your custom adsense code
<?php endif; ?>
<?php endforeach; ?>
Step-by-step tutorial for newbies on how to override default views-view-unformatted.tpl.php and achieve custom code after for example first and sixth row is here.