@@ -232,11 +232,12 @@ function get_archives($type='', $limit='', $format='html', $before = "", $after
232232}
233233
234234function get_calendar ($ daylength = 1 ) {
235- global $ wpdb , $ HTTP_GET_VARS , $ m , $ monthnum , $ year , $ timedifference , $ month , $ weekday , $ tableposts , $ posts ;
235+ global $ wpdb , $ HTTP_GET_VARS , $ m , $ monthnum , $ year , $ timedifference , $ month , $ weekday , $ tableposts , $ posts, $ querycount ;
236236
237237 // Quick check. If we have no posts at all, abort!
238238 if (!$ posts ) {
239239 $ gotsome = $ wpdb ->get_var ("SELECT ID from $ tableposts WHERE post_status = 'publish' AND post_category > 0 ORDER BY post_date DESC LIMIT 1 " );
240+ ++$ querycount ;
240241 if (!$ gotsome )
241242 return ;
242243 }
@@ -253,6 +254,7 @@ function get_calendar($daylength = 1) {
253254 $ thisyear = '' .intval (substr ($ m , 0 , 4 ));
254255 $ d = (($ w - 1 ) * 7 ) + 6 ; //it seems MySQL's weeks disagree with PHP's
255256 $ thismonth = $ wpdb ->get_var ("SELECT DATE_FORMAT((DATE_ADD(' $ {thisyear}0101', INTERVAL $ d DAY) ), '%m') " );
257+ ++$ querycount ;
256258 } elseif (!empty ($ m )) {
257259 $ calendar = substr ($ m , 0 , 6 );
258260 $ thisyear = '' .intval (substr ($ m , 0 , 4 ));
@@ -275,13 +277,15 @@ function get_calendar($daylength = 1) {
275277 AND post_status = 'publish'
276278 ORDER BY post_date DESC
277279 LIMIT 1 " );
280+ ++$ querycount ;
278281 $ next = $ wpdb ->get_row ("SELECT DISTINCT MONTH( post_date ) AS month, YEAR( post_date ) AS year
279282 FROM $ tableposts
280283 WHERE post_date > ' $ thisyear- $ thismonth-01'
281284 AND MONTH( post_date ) != MONTH( ' $ thisyear- $ thismonth-01' )
282285 AND post_status = 'publish'
283286 ORDER BY post_date ASC
284287 LIMIT 1 " );
288+ ++$ querycount ;
285289
286290 echo '<table id="wp-calendar">
287291 <caption> ' . $ month [zeroise ($ thismonth , 2 )] . ' ' . date ('Y ' , $ unixmonth ) . '</caption>
@@ -329,7 +333,7 @@ function get_calendar($daylength = 1) {
329333 AND YEAR(post_date) = $ thisyear
330334 AND post_status = 'publish'
331335 AND post_date < ' " . date ("Y-m-d H:i:s " , (time () + ($ time_difference * 3600 )))."' " , ARRAY_N );
332-
336+ ++ $ querycount ;
333337 if ($ dayswithposts ) {
334338 foreach ($ dayswithposts as $ daywith ) {
335339 $ daywithpost [] = $ daywith [0 ];
@@ -355,6 +359,7 @@ function get_calendar($daylength = 1) {
355359 ."AND post_date < ' " .date ("Y-m-d H:i:s " , (time () + ($ time_difference * 3600 )))."' "
356360 ."AND post_status = 'publish' "
357361 );
362+ ++$ querycount ;
358363 if ($ ak_post_titles ) {
359364 foreach ($ ak_post_titles as $ ak_post_title ) {
360365 if (empty ($ ak_titles_for_day ["$ ak_post_title ->dom " ])) { // first one
@@ -405,7 +410,8 @@ function get_calendar($daylength = 1) {
405410/***** Links *****/
406411function get_permalink ($ id =false ) {
407412 global $ post , $ wpdb , $ tableposts ;
408- global $ siteurl , $ blogfilename , $ querystring_start , $ querystring_equal ;
413+ global $ siteurl , $ blogfilename , $ querystring_start , $ querystring_equal , $ querycount ;
414+
409415 $ rewritecode = array (
410416 '%year% ' ,
411417 '%monthnum% ' ,
@@ -427,6 +433,7 @@ function get_permalink($id=false) {
427433 }
428434 } else { // if an ID is given
429435 $ idpost = $ wpdb ->get_row ("SELECT post_date, post_name FROM $ tableposts WHERE ID = $ id " );
436+ ++$ querycount ;
430437 if ('' != get_settings ('permalink_structure ' )) {
431438 $ unixtime = strtotime ($ idpost ->post_date );
432439 $ rewritereplace = array (
@@ -1350,7 +1357,7 @@ function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_orde
13501357 $ query .= " ORDER BY $ sort_column $ sort_order, post_date DESC " ;
13511358
13521359 $ categories = $ wpdb ->get_results ($ query );
1353-
1360+ ++ $ querycount ;
13541361 if (!$ categories ) {
13551362 if ($ list ) {
13561363 $ before = '<li> ' ;
@@ -1359,7 +1366,6 @@ function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_orde
13591366 echo $ before . "No categories " . $ after . "\n" ;
13601367 return ;
13611368 }
1362- ++$ querycount ;
13631369 if (intval ($ optionall ) == 1 ) {
13641370 $ all = apply_filters ('list_cats ' , $ all );
13651371 $ link = "<a href= \"" .$ file .$ querystring_start .'cat ' .$ querystring_equal .'all"> ' .$ all ."</a> " ;
@@ -1405,11 +1411,12 @@ function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_orde
14051411
14061412function comments_number ($ zero ='No Comments ' , $ one ='1 Comment ' , $ more ='% Comments ' , $ include_unapproved = false ) {
14071413 global $ id , $ comment , $ tablecomments , $ querycount , $ wpdb ;
1408- $ query = "SELECT COUNT(*) FROM $ tablecomments WHERE comment_post_ID = ' $ id' " ;
1414+ $ query = "SELECT COUNT(*) FROM $ tablecomments WHERE comment_post_ID = $ id " ;
14091415 if (false == $ include_unapproved ) {
14101416 $ query .= " AND comment_approved = '1' " ;
14111417 }
14121418 $ number = $ wpdb ->get_var ($ query );
1419+ ++$ querycount ;
14131420 if ($ number == 0 ) {
14141421 $ blah = $ zero ;
14151422 } elseif ($ number == 1 ) {
@@ -1438,9 +1445,10 @@ function comments_popup_script($width=400, $height=400, $file='b2commentspopup.p
14381445}
14391446
14401447function comments_popup_link ($ zero ='No Comments ' , $ one ='1 Comment ' , $ more ='% Comments ' , $ CSSclass ='' , $ none ='Comments Off ' ) {
1441- global $ id , $ b2commentspopupfile , $ b2commentsjavascript , $ post , $ wpdb , $ tablecomments , $ HTTP_COOKIE_VARS , $ cookiehash ;
1448+ global $ id , $ b2commentspopupfile , $ b2commentsjavascript , $ post , $ wpdb , $ querycount , $ tablecomments , $ HTTP_COOKIE_VARS , $ cookiehash ;
14421449 global $ querystring_start , $ querystring_equal , $ querystring_separator , $ siteurl ;
14431450 $ number = $ wpdb ->get_var ("SELECT COUNT(*) FROM $ tablecomments WHERE comment_post_ID = $ id AND comment_approved = '1' " );
1451+ ++$ querycount ;
14441452 if (0 == $ number && 'closed ' == $ post ->comment_status ) {
14451453 echo $ none ;
14461454 return ;
0 commit comments