Note that there are some explanatory texts on larger screens.

plurals
  1. PODrupal: How to get deeplink to comment?
    primarykey
    data
    text
    <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',"node/".$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, "node/$comment-&gt;nid", array("fragment" =&gt; "comment-$comment-&gt;cid")); ?&gt; </code></pre> <p>Note the little difference bettween Mikeker and my version. <code>array("fragment" =&gt; "comment-$comment-&gt;cid"));</code> and <code>array("query" =&gt; "comment-$comment-&gt;cid"));</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>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload