Insert an ad into Views Grid? I'm using the Views Grid layout and I'm looking for a way to place Google Adsense ads randomly within the grid. Here is the code in views-view-grid.tpl.php:

&lt;?php if (!empty($title)) : ?&gt;
  &lt;h3&gt;&lt;?php print $title; ?&gt;&lt;/h3&gt;
&lt;?php endif; ?&gt;
&lt;table class="&lt;?php print $class; ?&gt;"&lt;?php print $attributes; ?&gt;&gt;
  &lt;?php if (!empty($caption)) : ?&gt;
    &lt;caption&gt;&lt;?php print $caption; ?&gt;&lt;/caption&gt;
  &lt;?php endif; ?&gt;

  &lt;tbody&gt;
    &lt;?php foreach ($rows as $row_number =&gt; $columns): ?&gt;
      &lt;tr &lt;?php if ($row_classes[$row_number]) { print 'class="' . $row_classes[$row_number] .'"';  } ?&gt;&gt;
        &lt;?php foreach ($columns as $column_number =&gt; $item): ?&gt;
          &lt;td &lt;?php if ($column_classes[$row_number][$column_number]) { print 'class="' . $column_classes[$row_number][$column_number] .'"';  } ?&gt;&gt;
            &lt;?php print $item; ?&gt;
          &lt;/td&gt;
        &lt;?php endforeach; ?&gt;
      &lt;/tr&gt;
    &lt;?php endforeach; ?&gt;
  &lt;/tbody&gt;
&lt;/table&gt;


Is editing the template file the correct way to do this? I'm not a programmer so a lot of this is beyond me but I am willing to learn.
Nice attempt, but no the template file is not the best place for that.

I would work on including the ads in your View result rather than trying to hack the template file.

Does your view show rendered content?  Easy, make a new content type that contains your ads and include that content type in your filter.

Does your view show fields?  Same thing, just make sure the ad content type has the same fields as the content you're showing in the grid.