diff --git a/b2-include/b2template.functions.php b/b2-include/b2template.functions.php index ab9765c3e1..85f9364b49 100644 --- a/b2-include/b2template.functions.php +++ b/b2-include/b2template.functions.php @@ -162,20 +162,24 @@ function get_archives($type='', $limit='', $format='html') { if ('monthly' == $type) { ++$querycount; $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month` FROM $tableposts WHERE post_date < '$now' AND post_category > 0 AND post_status = 'publish' ORDER BY post_date DESC" . $limit); - foreach ($arcresults as $arcresult) { - $url = sprintf("%s%d%02d", $archive_link_m, $arcresult->year, $arcresult->month); - $text = sprintf("%s %d", $month[zeroise($arcresult->month,2)], $arcresult->year); - echo get_archives_link($url, $text, $format); - } + if ($arcresults) { + foreach ($arcresults as $arcresult) { + $url = sprintf("%s%d%02d", $archive_link_m, $arcresult->year, $arcresult->month); + $text = sprintf("%s %d", $month[zeroise($arcresult->month,2)], $arcresult->year); + echo get_archives_link($url, $text, $format); + } + } } elseif ('daily' == $type) { ++$querycount; $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth` FROM $tableposts WHERE post_date < '$now' AND post_category > 0 AND post_status = 'publish' ORDER BY post_date DESC" . $limit); - foreach ($arcresults as $arcresult) { - $url = sprintf("%s%d%02d%02d", $archive_link_m, $arcresult->year, $arcresult->month, $arcresult->dayofmonth); - $date = sprintf("%d-%02d-%02d 00:00:00", $arcresult->year, $arcresult->month, $arcresult->dayofmonth); - $text = mysql2date($archive_day_date_format, $date); - echo get_archives_link($url, $text, $format); - } + if ($arcresults) { + foreach ($arcresults as $arcresult) { + $url = sprintf("%s%d%02d%02d", $archive_link_m, $arcresult->year, $arcresult->month, $arcresult->dayofmonth); + $date = sprintf("%d-%02d-%02d 00:00:00", $arcresult->year, $arcresult->month, $arcresult->dayofmonth); + $text = mysql2date($archive_day_date_format, $date); + echo get_archives_link($url, $text, $format); + } + } } elseif ('weekly' == $type) { if (!isset($start_of_week)) { $start_of_week = 1; @@ -183,35 +187,39 @@ function get_archives($type='', $limit='', $format='html') { ++$querycount; $arcresults = $wpdb->get_results("SELECT DISTINCT WEEK(post_date, $start_of_week) AS `week`, YEAR(post_date) AS yr, DATE_FORMAT(post_date, '%Y-%m-%d') AS yyyymmdd FROM $tableposts WHERE post_date < '$now' AND post_category > 0 AND post_status = 'publish' ORDER BY post_date DESC" . $limit); $arc_w_last = ''; - foreach ($arcresults as $arcresult) { - if ($arcresult->week != $arc_w_last) { - $arc_year = $arcresult->yr; - $arc_w_last = $arcresult->week; - $arc_week = get_weekstartend($arcresult->yyyymmdd, $start_of_week); - $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']); - $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']); - $url = sprintf("%s/%s%sm%s%s%sw%s%d", $siteurl, $blogfilename, $querystring_start, - $querystring_equal, $arc_year, $querystring_separator, - $querystring_equal, $arcresult->week); - $text = $arc_week_start . $archive_week_separator . $arc_week_end; - echo get_archives_link($url, $text, $format); - } - } + if ($arcresults) { + foreach ($arcresults as $arcresult) { + if ($arcresult->week != $arc_w_last) { + $arc_year = $arcresult->yr; + $arc_w_last = $arcresult->week; + $arc_week = get_weekstartend($arcresult->yyyymmdd, $start_of_week); + $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']); + $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']); + $url = sprintf("%s/%s%sm%s%s%sw%s%d", $siteurl, $blogfilename, $querystring_start, + $querystring_equal, $arc_year, $querystring_separator, + $querystring_equal, $arcresult->week); + $text = $arc_week_start . $archive_week_separator . $arc_week_end; + echo get_archives_link($url, $text, $format); + } + } + } } elseif ('postbypost' == $type) { ++$querycount; $arcresults = $wpdb->get_results("SELECT ID, post_date, post_title FROM $tableposts WHERE post_date < '$now' AND post_category > 0 AND post_status = 'publish' ORDER BY post_date DESC" . $limit); - foreach ($arcresults as $arcresult) { - if ($arcresult->post_date != '0000-00-00 00:00:00') { - $url = $archive_link_p . $arcresult->ID; - $arc_title = stripslashes($arcresult->post_title); - if ($arc_title) { - $text = strip_tags($arc_title); - } else { - $text = $arcresult->ID; - } - echo get_archives_link($url, $text, $format); - } - } + if ($arcresults) { + foreach ($arcresults as $arcresult) { + if ($arcresult->post_date != '0000-00-00 00:00:00') { + $url = $archive_link_p . $arcresult->ID; + $arc_title = stripslashes($arcresult->post_title); + if ($arc_title) { + $text = strip_tags($arc_title); + } else { + $text = $arcresult->ID; + } + echo get_archives_link($url, $text, $format); + } + } + } } } /***** // About-the-blog tags *****/