Opened 17 years ago
Closed 15 years ago
#4832 closed defect (bug) (fixed)
In comments_popup_link(), why bomb out when on a page or single post?
Reported by: | 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)
Change History (8)
#3
@
15 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.
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