How To Include Drupal Comments In Section Targeting

How To Include Drupal Comments In Section Targeting

In a recent article, I stated that the latest adsense.module has integrated section targeting.

Today, I explain how to modify your theme so that section targeting applies to comments as well.

I am assuming that you will be using a phptemplate based theme.

What you need is  to modify the comment.tpl.php for your theme. This should look something like  this:

 <div class="comment">
<?php if ($picture) : ?>
<?php print $picture; ?>
<?php endif; ?>
<h3 class="title"><?php print $title; ?></h3>
<?php if ($new != '') : ?>
<span class="new"><?php print $new; ?></span>
<?php endif; ?>
<div class="submitted"><?php print $submitted; ?></div>
<div class="content"><?php print $content; ?></div>
<div class="links">&raquo; <?php print $links; ?></div>
</div>

What you need to do is wrap the content part in the section tags, like so: 

<div class="comment">
<?php if ($picture) : ?>
<?php print $picture; ?>
<?php endif; ?>
<h3 class="title"><?php print $title; ?></h3>
<?php if ($new != '') : ?>
<span class="new"><?php print $new; ?></span>
<?php endif; ?>
<div class="submitted"><?php print $submitted; ?></div>
<!-- google_ad_section_start -->
<div class="content"><?php print $content; ?></div>
<!-- google_ad_section_end -->
<div class="links">&raquo; <?php print $links; ?></div>
</div>

That is it, this is all you need to do. 

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • Lines and paragraphs break automatically.

More information about formatting options