Changeset 3716
- Timestamp:
- 04/19/2006 02:53:02 AM (19 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/comment-template.php
r3714 r3716 143 143 144 144 function get_comments_number( $post_id = 0 ) { 145 global $wpdb, $ comment_count_cache, $id;145 global $wpdb, $id; 146 146 $post_id = (int) $post_id; 147 147 … … 149 149 $post_id = $id; 150 150 151 // TODO: Remove SELECT. Use get_post(). 152 if ( !isset($comment_count_cache[$post_id]) ) 153 $comment_count_cache[$id] = $wpdb->get_var("SELECT comment_count FROM $wpdb->posts WHERE ID = '$post_id'"); 154 155 return apply_filters('get_comments_number', $comment_count_cache[$post_id]); 151 $post = get_post($post_id); 152 if ( ! isset($post->comment_count) ) 153 $count = 0; 154 else 155 $count = $post->comment_count; 156 157 return apply_filters('get_comments_number', $count); 156 158 } 157 159 … … 324 326 function comments_popup_link($zero='No Comments', $one='1 Comment', $more='% Comments', $CSSclass='', $none='Comments Off') { 325 327 global $id, $wpcommentspopupfile, $wpcommentsjavascript, $post, $wpdb; 326 global $comment_count_cache; 327 328 if (! is_single() && ! is_page()) { 329 // TODO: Use API instead of SELECT 330 if ( !isset($comment_count_cache[$id]) ) 331 $comment_count_cache[$id] = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = $id AND comment_approved = '1';"); 332 333 $number = $comment_count_cache[$id]; 334 335 if (0 == $number && 'closed' == $post->comment_status && 'closed' == $post->ping_status) { 328 329 if ( is_single() || is_page() ) 330 return; 331 332 $number = get_comments_number($id); 333 334 if ( 0 == $number && 'closed' == $post->comment_status && 'closed' == $post->ping_status ) { 336 335 echo $none; 337 336 return; 338 } else { 339 if (!empty($post->post_password)) { // if there's a password 340 if ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie 341 echo(__('Enter your password to view comments')); 342 return; 343 } 344 } 345 echo '<a href="'; 346 if ($wpcommentsjavascript) { 347 if ( empty($wpcommentspopupfile) ) 348 $home = get_settings('home'); 349 else 350 $home = get_settings('siteurl'); 351 echo $home . '/' . $wpcommentspopupfile.'?comments_popup='.$id; 352 echo '" onclick="wpopen(this.href); return false"'; 353 } else { // if comments_popup_script() is not in the template, display simple comment link 354 if ( 0 == $number ) 355 echo get_permalink() . '#respond'; 356 else 357 comments_link(); 358 echo '"'; 359 } 360 if (!empty($CSSclass)) { 361 echo ' class="'.$CSSclass.'"'; 362 } 363 echo ' title="' . sprintf( __('Comment on %s'), $post->post_title ) .'">'; 364 comments_number($zero, $one, $more, $number); 365 echo '</a>'; 366 } 367 } 337 } 338 339 if ( !empty($post->post_password) ) { // if there's a password 340 if ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie 341 echo(__('Enter your password to view comments')); 342 return; 343 } 344 } 345 346 echo '<a href="'; 347 if ($wpcommentsjavascript) { 348 if ( empty($wpcommentspopupfile) ) 349 $home = get_settings('home'); 350 else 351 $home = get_settings('siteurl'); 352 echo $home . '/' . $wpcommentspopupfile.'?comments_popup='.$id; 353 echo '" onclick="wpopen(this.href); return false"'; 354 } else { // if comments_popup_script() is not in the template, display simple comment link 355 if ( 0 == $number ) 356 echo get_permalink() . '#respond'; 357 else 358 comments_link(); 359 echo '"'; 360 } 361 362 if (!empty($CSSclass)) { 363 echo ' class="'.$CSSclass.'"'; 364 } 365 echo ' title="' . sprintf( __('Comment on %s'), $post->post_title ) .'">'; 366 comments_number($zero, $one, $more, $number); 367 echo '</a>'; 368 368 } 369 369 -
trunk/wp-includes/functions.php
r3714 r3716 1314 1314 1315 1315 function update_post_caches(&$posts) { 1316 global $post_cache, $category_cache, $ comment_count_cache, $post_meta_cache;1316 global $post_cache, $category_cache, $post_meta_cache; 1317 1317 global $wpdb; 1318 1318 … … 1325 1325 $post_id_array[] = $posts[$i]->ID; 1326 1326 $post_cache[$posts[$i]->ID] = &$posts[$i]; 1327 $comment_count_cache[$posts[$i]->ID] = $posts[$i]->comment_count;1328 1327 } 1329 1328
Note: See TracChangeset
for help on using the changeset viewer.