WordPress.org

Support

Support » How-To and Troubleshooting » Link to exact comment

Link to exact comment

  • I have a few different themes and I am not sure what in the comment.php code works to link to the individual comment.

    For example if I want to put a link in an entry pointing to comment #3748 it will work with some of my themes but two themes it will not work to link, it will only link to the entry that has the link, but not the individual comment.

    What code should be added to the comments.php to make it allow it to link to the individual comment?

    I hope this makes sense, it is just some entries have several hundred comments and it is like looking for a needle in a haystack.

    TIA

Viewing 6 replies - 1 through 6 (of 6 total)
  • You want to use comment_ID() in combination with some element of each comment that can be assigned the ID attribute. If comments are in list (<li>) elements, you could do:

    <li id="comment-<?php comment_ID(); ?>">

    Then #comment-3748 would become the fragment identifier for that comment. (#3748 would be considered invalid XHTML, as fragment idents cannot start with a number.)

    Thanks Kaf

    <li id=”comment-<?php comment_ID() ?>”>

    The above is what I had that worked in the themes that did link correctly.

    I added the code, you will notice I am missing the semi-colon ; but both work. Question is I know have a bullet outside the comment area that was not there before?

    any ideas?

    http://nvfc.us/blog/archives/217#comment-3991

    The semicolon is used to define the end of a PHP statement. In most operating environments a single PHP statement within <?php ?> tags can be used without having to close it with a semicolon.

    I can suggest how to remove the bullets through your css, but as you didn’t originally have comments in <li> elements, you might want to remove them and instead go with altering your commentid div:

    <div class="commentid" id="comment-<?php comment_ID(); ?>">

    I tried that, it worked and got rid of the bullets but the text was all <h1>and large, I opted for putting the bullets back in,

    Thanks lets try the css route.

    Just add this to your stylesheet:

    #content li {
    list-style: none;
    }

    Notes: <li> tags must be nested in a <ul> or <ol> element to be valid X/HTML. Also, without being able to define the comments section for this, all <li> tags under the content div will be affected by the css declaration above, but you can *fix* this by defining an id for your <ul> or <ol> element (let’s say “comments”) and using for your declaration:

    #comments li {
    list-style: none;
    }

    Thanks Kaf, that worked, I guess I was just brain dead this afternoon.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Link to exact comment’ is closed to new replies.