WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] php comment_link not working for zero quantity (5 posts)

  1. shilojean
    Member
    Posted 4 years ago #

    Hello all,
    I'm using the comment_link tag to pull comment counts and use them as clickable entry points to posts.

    Problem is, it's not working for posts with zero comments! Works fine for posts with one or multiple comments, but I can't figure out how to get zero working.

    here's my tag:

    <a href="<?php comments_link(); ?>">
    <?php comments_number(__('0'), __('1'), __('%')); ?></a>

    It seems like such a simple tag, what am I doing wrong?

    edited for clarity.

  2. alchymyth
    Forum Moderator
    Posted 4 years ago #

    what is 'Problem is, it's not working for posts with zero comments!' ?

    maybe it has to do with the anchor points in your theme:
    as far as i know, an empty comments_link would point to an anchor #respond while one with comments would point to #comments

  3. shilojean
    Member
    Posted 4 years ago #

    Hi alchymyth, thanks for your response and suggestions.

    I initially thought when I posted this thread that the comment link (to comment count) was working for comments counts of 1 or above, but not zero.
    However, I just realized that the issue is NOT a comment count issue, that it's the first post on any page, regardless of the count. It just so happened that all of the posts I was looking at had zero comments AND happened to be at the tops of their pages.

    Example: If you try to click through the comment link on the first post on this page:
    http://www.yikesmachine.com/2009/11/page/2/
    You'll see that the background link works, but the comment count itself doesn't link to anything.
    However, if you try any other comment count other than the first post on the page, both the background and the count will click through.

    This appears to hold true regardless of how posts are sorted - main index, search results, category results, archives etc. - any format where multiple posts are to be displayed, the first one always doesn't work but the rest are fine.

    Clear as mud?

    I'm just learning the basics of php and theme development, so I'm not familiar with anchor points, but I'll go look them up and see if that may be a possibility for my issue.

    Thanks again. I really appreciate your help.

  4. alchymyth
    Forum Moderator
    Posted 4 years ago #

    if you click on the '0 comments' of the first post on the link you posted ('candy floss'), you get to a single post, where it says in small writing beneath the text 'comments are closed for this post' - ok.

    if you click on the '0 comments' of the first post of archives july ('kitchens'), you get the comments input form beneath the post - ok.

    so all seems to be working fine.

    see if all the posts, where you think the comment link is not working, have comments disabled.

  5. shilojean
    Member
    Posted 4 years ago #

    Well huh. In completely unrelated news, my theme is a hacked-up and reworked version of a different ready-made theme (Corporate by Ori Pearl) and I had changed the post size in style.css, but not in screen.css, the blueprintcss file. (that I didn't even realize existed because it doesn't show in my wordpress editor, whoops!)

    This css incongruence was causing me some alignment issues with my "older" and "newer" images, so I got in there and fiddled around with it until everything was lining up correctly. Somehow, magically, this also appears to have fixed my issue with the comments!

    Thanks again for your help, it's deeply appreciated.

    Lesson of the day: Janky CSS can mess up more than appearances.

Topic Closed

This topic has been closed to new replies.

About this Topic