How To Include Drupal Comments In Section Targeting

Sponsored Links

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

  • All spam and irrelevant comments will be deleted.
  • Comments posted here will take some time to appear on the site. Do not post your comment again if you do not see it. Just be patient and it will be published.
  • Note that what you post here will be publicly available on the web and will be indexed in search engines.
  • We reserve the right to unpublish any comments without stating the reasons for that.
  • All postings are subject to our Terms of use
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