boardom Forum Index boardom
b2 message board
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Total posts for the month/week

 
Post new topic   Reply to topic    boardom Forum Index -> Hacks
View previous topic :: View next topic  
Author Message
mikelittle



Joined: 11 May 2002
Posts: 376
Location: UK

PostPosted: Sat Aug 17, 2002 4:06 pm    Post subject: Total posts for the month/week Reply with quote

Here's another. This one gives you total posts for the month/week in your archives list by month/week

in b2archives.php

the code
Code:

if ($archive_mode == "monthly") {
   $arc_sql="SELECT DISTINCT YEAR(post_date), MONTH(post_date) FROM $tableposts WHERE post_date < '$now' AND post_category > 0 ORDER BY post_date DESC";
   $querycount++;


becomes
Code:

if ($archive_mode == "monthly") {
   $arc_sql="SELECT DISTINCT YEAR(post_date), MONTH(post_date), count(*) as posts FROM $tableposts WHERE post_date < '$now' AND post_category > 0 GROUP BY MONTH(post_date) ORDER BY post_date DESC";
   $querycount++;


and a few lines down a new line after the closing anchor tag so that
Code:

echo "</a>";
echo $archive_line_separator."\n";

becomes
Code:

echo "</a>";
echo ' (' . $arc_row["posts"] . ' post' . (($arc_row["posts"] > 1) && ($arc_row["posts"] != 0) ? 's' : '') .')';
echo $archive_line_separator."\n";


similarly at the test for weekly the code
Code:

} elseif ($archive_mode == "weekly") {
   if (!isset($start_of_week)) {
      $start_of_week = 1;
   }
   $arc_sql="SELECT DISTINCT YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date), WEEK(post_date) FROM $tableposts WHERE post_date < '$now' AND post_category > 0 ORDER BY post_date DESC";
   $querycount++;


becomes

Code:

} elseif ($archive_mode == "weekly") {
   if (!isset($start_of_week)) {
      $start_of_week = 1;
   }
   $arc_sql="SELECT DISTINCT YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date), WEEK(post_date), count(*) as posts FROM $tableposts WHERE post_date < '$now' AND post_category > 0 GROUP BY WEEK(post_date) ORDER BY post_date DESC";
   $querycount++;


and a few lines down
Code:

echo "</a>";
echo $archive_line_separator."\n";


becomes
Code:

echo "</a>";
echo ' (' . $arc_row["posts"] . ' post' . (($arc_row["posts"] > 1) && ($arc_row["posts"] != 0) ? 's' : '') .')';
echo $archive_line_separator."\n";


See http://zed1.com/b2 left hand column for an example.


Enjoy
Mike
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
mikelittle



Joined: 11 May 2002
Posts: 376
Location: UK

PostPosted: Tue Nov 05, 2002 1:25 am    Post subject: Reply with quote

Minor update: I believe count(column) is more efficient than count(*);
[php:1:de843ce355]<?php
if ($archive_mode == 'monthly') {
$arc_sql="SELECT DISTINCT YEAR(post_date), MONTH(post_date), count(ID) as posts FROM $tableposts WHERE post_date < '$now' AND post_category > 0 GROUP BY MONTH(post_date) ORDER BY post_date DESC";
$querycount++;
$arc_result=mysql_query($arc_sql) or die($arc_sql.'<br />'.mysql_error());
while($arc_row = mysql_fetch_array($arc_result)) {
$arc_year = $arc_row['YEAR(post_date)'];
$arc_month = $arc_row['MONTH(post_date)'];
echo "<a href=\"$archive_link_m$arc_year".zeroise($arc_month,2).'">';
echo $month[zeroise($arc_month,2)].' '.$arc_year;
echo '</a>';
echo ' (' . $arc_row['posts'] . ' post' . (($arc_row['posts'] > 1) && ($arc_row['posts'] != 0) ? 's' : '') .')';
echo $archive_line_separator."\n";
}
//skip daily section
} elseif ($archive_mode == 'weekly') {
if (!isset($start_of_week)) {
$start_of_week = 1;
}
$arc_sql="SELECT DISTINCT YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date), WEEK(post_date), count(ID) as posts FROM $tableposts WHERE post_date < '$now' AND post_category > 0 GROUP BY WEEK(post_date) ORDER BY post_date DESC";
$querycount++;
$arc_result=mysql_query($arc_sql) or die($arc_sql.'<br />'.mysql_error());
$arc_w_last = '';
while($arc_row = mysql_fetch_array($arc_result)) {
$arc_year = $arc_row['YEAR(post_date)'];
$arc_w = $arc_row['WEEK(post_date)'];
if ($arc_w != $arc_w_last) {
$arc_w_last = $arc_w;
$arc_ymd = $arc_year.'-'.zeroise($arc_row['MONTH(post_date)'],2).'-' .zeroise($arc_row['DAYOFMONTH(post_date)'],2);
$arc_week = get_weekstartend($arc_ymd, $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']);
echo "<a href=\"$siteurl/".$blogfilename."?m=$arc_year&w=$arc_w\">";
echo $arc_week_start.$archive_week_separator.$arc_week_end;
echo '</a>';
echo ' (' . $arc_row['posts'] . ' post' . (($arc_row['posts'] > 1) && ($arc_row['posts'] != 0) ? 's' : '') .')';
echo $archive_line_separator."\n";
}
}
?>[/php:1:de843ce355]

Note: I've skipped the daily section
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
sharmaine



Joined: 27 Oct 2003
Posts: 27

PostPosted: Tue Nov 04, 2003 9:32 am    Post subject: Reply with quote

This is great! Thank you so much!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    boardom Forum Index -> Hacks All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2 © 2001, 2002 phpBB Group