Make WordPress Core

Opened 12 years ago

Closed 9 years ago

#19893 closed enhancement (fixed)

get_comments_link() doesn't link properly if there are no responses

Reported by: cgrymala's profile cgrymala Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.4 Priority: normal
Severity: normal Version:
Component: Comments Keywords: has-patch needs-unit-tests commit
Focuses: Cc:


Since the current implementation of get_comments_link() simply returns the permalink with #comments appended to the end of it, and the HTML element with an ID of comments only exists when existing comments are wrapped inside of it, it doesn't lead to anything when there are 0 comments on the post.

I've attached a patch that checks whether there are any comments on the post or not; and, if not, it appends #respond to the end of the link; otherwise it appends #comments.

Attachments (3) (479 bytes) - added by cgrymala 12 years ago.
get_comments_link() checks number of comments before generating link
19893.diff (654 bytes) - added by wonderboymusic 9 years ago.
19893.2.diff (593 bytes) - added by netweb 9 years ago.

Download all attachments as: .zip

Change History (11)

12 years ago

get_comments_link() checks number of comments before generating link

#1 @solarissmoke
12 years ago

In the bundled themes (and I suspect most other themes as well), #respond is a descendant of #comments anyway, so this wouldn't make any difference?

#2 @cgrymala
12 years ago

I was going by the code included in wp-includes/theme-compat/comments.php, which uses #comments as an ID for the <h3> tag at the top of the comment list. That <h3> is only output when have_comments() is true (it's not wrapping anything, and doesn't even exist if there are no comments).

I realize that that file is deprecated, but if that's the way WordPress builds the comment area by default, that might be the way a lot of people are using it.

#3 @chriscct7
9 years ago

  • Keywords dev-feedback needs-refresh added; has-patch removed
  • Severity changed from minor to normal

Needs refresh because of #19210

9 years ago

#4 @wonderboymusic
9 years ago

  • Keywords has-patch added; dev-feedback needs-refresh removed
  • Milestone changed from Awaiting Review to 4.4

Makes a lot of sense: [attached:19893.diff refreshed]

#5 @wonderboymusic
9 years ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 34075:

Comments: get_comments_link() should return a link with #respond as the hash instead of #comments if get_comments_number() returns 0.

Props cgrymala, wonderboymusic.
Fixes #19893.

#6 @swissspidy
9 years ago

  • Keywords needs-unit-tests added

Looks like Tests_Feed_RSS2::test_items is failing after this change.

Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@

9 years ago

#7 @netweb
9 years ago

  • Keywords commit added
  • Resolution fixed deleted
  • Status changed from closed to reopened

19893.2.diff fixes the comment link response in Tests_Feed_RSS2::test_items() as there are no comments created for the created posts in this test, therefore per r34075 the comment link to each post in the test should end in #respond and not #comment

#8 @jeremyfelt
9 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 34092:

Tests: Update Tests_Feed_RSS::test_items to expect new comment permalink structure.

Introduced in [34075] for posts without comments.

Props netweb.
Fixes #19893.

Note: See TracTickets for help on using tickets.