title: Drupal: How to get deeplink to comment?
body: <p>I need to build and print a deeplink to any given comment. So that the user can directly access the specific comment with just clicking a link. I could not find a native drupal function to get this so i build it my own.</p>
  <h2>My solution</h2>
  <pre><code>&lt;?php
      global $base_url;
      $base = drupal_lookup_path('alias',&quot;node/&quot;.$node-&gt;nid);
      $path = $base_url.'/'.$base.'#comment-'.$comment-&gt;cid;
  
      $link_options = array('html'=&gt; $html);
      $commentlink = l($date, $path, $link_options);
  ?&gt;
  </code></pre>
  <p>To print the link you only have to call <code>&lt;?php print $commentlink;?&gt;</code>. But i'm pretty sure there is better and much more drupal like way to solve the problem.</p>
  <h2>The Better Way</h2>
  <p>Mikeker did it :) As he suggested here are the solution.</p>
  <pre><code>&lt;?php
   $commentlink = l(
      $date,
      &quot;node/$comment-&gt;nid&quot;,
      array(&quot;fragment&quot; =&gt; &quot;comment-$comment-&gt;cid&quot;));
  ?&gt;
  </code></pre>
  <p>Note the little difference bettween Mikeker and my version. <code>array(&quot;fragment&quot; =&gt; &quot;comment-$comment-&gt;cid&quot;));</code> and <code>array(&quot;query&quot; =&gt; &quot;comment-$comment-&gt;cid&quot;));</code></p>
  <p>The query param will add an <code>?</code> to the url. So your path looks like</p>
  <pre><code>//…query
  http://example.com/path/to/node?comment-2
  </code></pre>
  <p>In opposite to my solution (fragment):</p>
  <pre><code>//…fragment
  http://example.com/path/to/node#comment-2
  </code></pre>
  <p><strong>Note:</strong>
  Do not include the leading '#' character to a fragment identifier. It will be added by drupal.</p>