Support » Plugins » Comments Enabled? Hack

  • I wanted to hide my comments links when comments were disabled on a post, so wrote a quick (well, when you decide you should learn PHP to do the hack, it takes a little longer) hack that can be used as a substitute for comments_popup_link(). smart_comments_popup_link(), which takes the same arguments as comments_popup_link(), only displays the link if comments are open or at least one comment has already been posted (and moderated, if that option is set). It differs from just setting the last argument of comments_popup_link() to ” because it depends only on comments, not on trackbacks or pingbacks. There’s probably some room for improvement in this regard. Any advice for improvement (or actual improvements) will be appreciated, since I’m trying to learn.
    Add the following to the my-hacks.php file:
    function smart_comments_popup_link($zero='No Comments', $one='1 Comment', $more='% Comments', $CSSclass='', $none='Comments Off') {
    global $wpdb, $tableposts, $tablecomments, $id;
    $comments_enabled = $wpdb->get_results("SELECT comment_status FROM $tableposts WHERE id=$id");
    $comments_exist = $wpdb->get_var("SELECT COUNT(*) FROM $tablecomments WHERE comment_post_ID = $id AND comment_approved = '1'") > 0;
    if (($comments_enabled[0]->comment_status == 'open') || $comments_exist) {
    comments_popup_link($zero, $one, $more, $CSSclass, $none);

Viewing 3 replies - 1 through 3 (of 3 total)
  • Incidentally, if anyone knows a better way of showing that code, please advise. I was going to put it up at the wiki, but I can’t seem to log into it to modify it.

    Most likely your problem with the wiki is because your user name is too short, it happened to others with short names and me as well even with 4 letters. Dunno why, but making up a longer user name seems to fix it.

    Now pluginized. See the wiki link in the post immediately above.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Comments Enabled? Hack’ is closed to new replies.