Make WordPress Core

Opened 18 years ago

Closed 16 years ago

#4832 closed defect (bug) (fixed)

In comments_popup_link(), why bomb out when on a page or single post?

Reported by: jeremyvisser's profile JeremyVisser Owned by:
Milestone: 2.8 Priority: normal
Severity: normal Version:
Component: Template Keywords: has-patch commit
Focuses: Cc:

Description

In the comments_popup_link() function in wp-includes/comment-template.php, the first two lines of code make the function return if it is being called from a page or single post.

if ( is_single() || is_page() )
	return;

So, the following template tag that you'd normally use in a post loop when displaying, say, the home page:

<?php comments_popup_link('No responses (be the first!)', '(One response)', '(% responses)'); ?>

...would show up as blank if you used it on a page or single post, because of the aforementioned code.

Now, I'm working on a mockup theme, which only uses comments in the comment popup (I insert the comments_popup_script() into the header, making comments_popup_link() bring up a popup window instead of linking to get_the_permalink() . '#comments'), and bringing the comment popup works great form the index page.

However, I also want to be able to launch the popup window from the permalink (I don't want any comments directly printed on the single post), but this code:

if ( is_single() || is_page() )
	return;

...is preventing me.

So, I worked around it by adding a force_comments_popup_link() function in functions.php of my theme, which is exactly the same as comments_popup_link(), but doesn't contain the ( is_single() || is_page() ) jurgle. And guess what -- it works great.

So, is that code really necessary? Could it be removed? Or, could a $force = false be added to the parameter list?

(The latter might be desirable, as I think some themes depend on the functionality of comments_popup_link() being blank at times.)

Environment

  • WordPress 2.2.2
  • WordPress trunk (r5954)

Attachments (2)

4832.001.diff (629 bytes) - added by AaronCampbell 17 years ago.
4832.2.diff (626 bytes) - added by sivel 16 years ago.
Updated for current trunk revision

Download all attachments as: .zip

Change History (8)

#1 @AaronCampbell
17 years ago

  • Keywords has-patch dev-feedback added
  • Milestone changed from 2.9 to 2.7

I agree with Jeremy. I know comments_popup_link is not USUALLY used on a static page, but it seems like you should be ABLE to use it on a static page. Especially with static front pages.

I think it's rather common to have a static front page, with a small section where the most recent, most popular, or featured posts are placed. It seems like a serious waste to have to duplicate the entire function just to drop a 2 line check.

I'm attaching a patch for 2.7

#2 @markjaquith
17 years ago

  • Milestone changed from 2.7 to 2.8

#3 @AaronCampbell
17 years ago

I'm certainly not going to argue with this getting pushed to 2.8, but could we push it in early in 2.8? It really would be nice to have.

@sivel
16 years ago

Updated for current trunk revision

#4 @sivel
16 years ago

  • Cc matt@… added
  • Keywords commit added; dev-feedback removed

+1

Users should be restricted if they want to use this on a page or single post.

Updated patch for current trunk revision.

#5 @sivel
16 years ago

Users should *not* be restricted is what I meant to write.

#6 @ryan
16 years ago

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

(In [10704]) Allow comments_popup_link() for is_single and is_page. Props AaronCampbell, sivel. fixes #4832

Note: See TracTickets for help on using tickets.