WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#18259 closed enhancement (worksforme)

Comment_ID() should be relative to the article

Reported by: gazpachu Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.2.1
Component: Comments Keywords:
Focuses: Cc:

Description

After posting a comment, the anchor to the comment_ID is attached to the URL to send the user to his new comment.

This comment_ID should be relative to the article instead of showing the ID of the last comment in our wordpress DB.

i.e. I'm getting "<li id="comment-4833" ..." in an article that has two comments. And the URL is: "http://domain.ltd/post-name#comment4833", when it should be "http://domain.ltd/post-name#comment2"

The code:

<li <?php if($depth > 1) {echo comment_class('comment-replied');}  else {echo comment_class();};  ?> id="comment-<?php comment_ID() ?>">

Change History (6)

comment:1 ocean903 years ago

  • Type changed from defect (bug) to enhancement

Marking as an enhancement because it's not a bug, it's intentionally.

Also why do you need this? If it's #2 or #9999, all the same to me. The main point is that it scrolls to the comment.

comment:2 gazpachu3 years ago

It's a matter of semantics. A #4833 ID doesn't add any meaning to the anchor/URL.

Regards

comment:3 xknown3 years ago

I do not think it worths the effort for doing this in the core. This functionality depends on how themes are coded, for example some of them show the trackbacks/pingbacks in the comment list, others do not. The problem is, when a comment is posted, you would not have a reliable way to determine the last relative id to do the redirection.

You can do it in your theme, though. You have the comment_post_redirect filter to modify the url used after posting a comment.

Last edited 3 years ago by xknown (previous) (diff)

comment:4 gazpachu3 years ago

With comment_post_redirect I cannot add a custom ID relative to the number of comments in the post. Do you think is it possible to pass that info to the filter?

comment:5 ocean903 years ago

  • Keywords close added; needs-patch removed

Sure, with the use of wp_count_comments.

comment:6 ocean903 years ago

  • Keywords close removed
  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Because it's already possible closed as works for me.

(And it seems like it works for you too, #18277)

Note: See TracTickets for help on using tickets.