2009-07-30 14:46:56 - Article

wordpress comment count as a button

Content.exe

Styling the wordpress comment count as a button/icon etc can be tricky because the normal call to the comments

comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)')); 

formats the output as an anchor point with the correct link, alt tags etc already set up.

So in order to intercept this and then add you own anchor point with divs/imagery etc you need to make a custom request


// SQL
$SQL = "SELECT COUNT(*) AS Count FROM $wpdb->comments WHERE comment_approved='1'";
$SQL.= "AND comment_post_ID='".intval($post->ID)."'";

// Sort the array into a string prefixed with 'Comments '
list($comments) = $wpdb->get_results($SQL, ARRAY_A); 	
$comments='Comments ('.$comments['Count'].')';

// generate the alt and title tags
$alt = 'Comment on '.$post->post_title;

// echo the button if this is not a single and not a page
if (!is_single() && !is_page()) {

// anchor open
echo '';

// complex formatting rules for the comment pop up, go here
echo $comments;

// anchor close
echo '';
}

The above does exactly the same, formats the link etc, but now you can access the anchor point directly and format it your own way.

Comments.log - 2 entries

2 responses to “wordpress comment count as a button

  1. Free
    This will help me a lot with wordpress maintenance and commenting service. thank you.
  2. Kandace Cheung
    Interesting Post, highly informative at the least. Keep up your good work bro/lad. hehe Much Love

Leave a Response

System Notice: Your email address will not be published. Required fields are marked with *

LOADING...
Initializing CyberDev systems...