 |
boardom b2 message board
|
View previous topic :: View next topic |
Author |
Message |
Cyberian75
Joined: 26 Sep 2002 Posts: 1278 Location: Oregon
|
Posted: Thu Jan 02, 2003 9:14 pm Post subject: b2archives.php with 'more' feature -- updated |
|
|
You can use this in place of the current b2archives.php file. With this, you can either include it to display the archive links or link to the file itself for a stand-alone archives page. By the way, this is for inexperienced users.
As an include, it will only list 4 archive links excluding the current month, which you can change/define. As a stand-alone, it will list all archive links.
Update:
-----
I have modified the monthly archives so that you can limit the number of links to display on your template, and if there are more months than the number of months displayed, this will display "# more . . ." as a link. Clicking on this link would take you to the stand-alone archives page with all month listed.
This only works for monthly archives for now.
-----
You can edit the HTML section to suit your site. You can see it in action on my journal site at here.
Code: |
<?php
if (!isset($showall)) {
$showall = 0;
}
if ($showall == 1) {
?>
//start editing
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" />
<html lang="en-us">
<head>
<title>Michael H. Park's Cyber Journal :: All Archives</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="iestyles.css" type="text/css" />
</head>
<body>
<h3>All Archives</h3>
//stop editing
<?php } ?>
<?php
// *** b2 Archive file
require_once("./b2config.php");
require_once("$b2inc/b2functions.php");
dbconnect();
function count_month_posts($year, $month) {
global $tableposts;
$count = mysql_query("SELECT COUNT(*) FROM $tableposts WHERE (YEAR(post_date) = '$year' AND MONTH(post_date) = '$month')");
$count = mysql_result($count,0);
return $count;
}
// this is what will separate your archive links
$archive_line_separator = "<br />";
// this is what will separate dates on weekly archive links
$archive_week_separator = " - ";
// archive link url
$archive_link_m = "$siteurl/".$blogfilename."?m="; # monthly archive
$archive_link_w = "$siteurl/".$blogfilename."?w="; # weekly archive
$archive_link_p = "$siteurl/".$blogfilename."?p="; # post-by-post archive
// over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
$archive_date_format_over_ride = 0;
// options for daily archive (only if you over-ride the general date format)
$archive_day_date_format = "Y/m/d";
// options for weekly archive (only if you over-ride the general date format)
$archive_week_start_date_format = "Y/m/d";
$archive_week_end_date_format = "Y/m/d";
// --- //
$dateformat=get_settings("date_format");
$time_difference=get_settings("time_difference");
if (!$archive_date_format_over_ride) {
$archive_day_date_format = $dateformat;
$archive_week_start_date_format = $dateformat;
$archive_week_end_date_format = $dateformat;
}
if (basename($HTTP_SERVER_VARS["SCRIPT_FILENAME"]) == "b2archives.php")
include ("blog.header.php");
if (!isset($querycount)) {
$querycount = 0;
}
$now = date("Y-m-d H:i:s",(time() + ($time_difference * 3600)));
//begin 'more' hack
$arc_limit = 4; //define the number of months to display when included
$loopbr = 0;
//end 'more' hack
if ($archive_mode == "monthly") {
$arc_sql="SELECT DISTINCT YEAR(post_date), MONTH(post_date) FROM $tableposts WHERE post_date < '$now' AND post_category > 0 AND MONTH(post_date) <> MONTH('$now') ORDER BY post_date DESC";
$querycount++;
$arc_result=mysql_query($arc_sql) or die($arc_sql."<br />".mysql_error());
$arcnum_result = mysql_num_rows($arc_result);
while($arc_row = mysql_fetch_array($arc_result)) {
$arc_year = $arc_row["YEAR(post_date)"];
$arc_month = $arc_row["MONTH(post_date)"];
$temp_count = count_month_posts($arc_year, $arc_month);
echo "<a href=\"$archive_link_m$arc_year".zeroise($arc_month,2).'">';
echo $month[zeroise($arc_month,2)].' '.$arc_year;
echo '</a>';
echo ' <span class = "smalltext">('.$temp_count.')</span>';
echo $archive_line_separator."\n";
//begin 'more' hack
$loopbr++;
if ($showall == 0 && $loopbr == $arc_limit) {
break;
}
//end 'more' hack
}
//begin 'more' hack
if ($showall == 0 && $arc_limit < $arcnum_result) {
$arcnum_diff = $arcnum_result - $arc_limit;
echo '<br />(<a href="/b2archives.php?showall=1">'.$arcnum_diff.' more...</a>)';
}
//end 'more' hack
} elseif ($archive_mode == "daily") {
$arc_sql="SELECT DISTINCT YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) FROM $tableposts WHERE post_date < '$now' AND post_category > 0 AND YEAR(post_date) = YEAR('$now') AND DAYOFMONTH(post_date) < DAYOFMONTH('$now') 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)"];
$arc_dayofmonth = $arc_row["DAYOFMONTH(post_date)"];
echo "<a href=\"$archive_link_m$arc_year".zeroise($arc_month,2).zeroise($arc_dayofmonth,2)."\">";
echo mysql2date($archive_day_date_format, $arc_year."-".zeroise($arc_month,2)."-".zeroise($arc_dayofmonth,2)." 00:00:00");
# echo $month[zeroise($arc_month,2)]." $arc_year";
echo "</a>";
echo $archive_line_separator."\n";
}
} 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 AND YEAR(post_date) = YEAR('$now') AND DAYOFMONTH(post_date) < DAYOFMONTH('$now') 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 $archive_line_separator."\n";
}
}
} elseif ($archive_mode == "postbypost") {
$requestarc = " SELECT ID,post_date,post_title FROM $tableposts WHERE post_date < '$now' AND post_category > 0 AND YEAR(post_date) = '2002' ORDER BY post_date DESC";
$querycount++;
$resultarc = mysql_query($requestarc);
while($row=mysql_fetch_object($resultarc)) {
if ($row->post_date != "0000-00-00 00:00:00") {
echo "<a href=\"$archive_link_p".$row->ID."\">";
$arc_title = stripslashes($row->post_title);
if ($arc_title) {
echo strip_tags($arc_title);
} else {
echo $row->ID;
}
echo "</a>";
echo $archive_line_separator."\n";
}
}
}
#echo $querycount."<br />\n";
#timer_stop(1,8);
if ($showall == 1) {
?>
//start editing
<br /><br /><br />
<span style="color: #0099CC">::</span> <a href="javascript:history.go(-1);">return to the previous screen</a>
</body>
</html>
//stop editing
<?php } ?>
|
_________________ Michael P.

Last edited by Cyberian75 on Sat Feb 01, 2003 11:02 pm; edited 10 times in total |
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1278 Location: Oregon
|
Posted: Mon Jan 06, 2003 6:04 am Post subject: |
|
|
Updated....  _________________ Michael P.
 |
|
Back to top |
|
 |
scrazynet11
Joined: 18 Nov 2002 Posts: 41 Location: Rio de Janeiro, Brazil
|
Posted: Tue Jan 07, 2003 9:07 am Post subject: Lazy |
|
|
I´m too lazy, is there anyplace I can see that working??  _________________ - Scrazynet
"To be or not to be, that´s the mothephuc**ing Question "
http://www.loukelicioso.net |
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1278 Location: Oregon
|
|
Back to top |
|
 |
Tanman
Joined: 28 Nov 2002 Posts: 36
|
Posted: Sun Jan 12, 2003 4:49 am Post subject: |
|
|
Hi Michael,
Can you please elaborate a bit more on exactly where you put the new entries. I am rather new, and its just a tad bit confusing where you actually entered in the new bits.
This "mod" is what was looking for, thanks for making it available.  |
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1278 Location: Oregon
|
Posted: Sun Jan 12, 2003 7:08 am Post subject: |
|
|
You can replace the entire thing. It's much easier that way. And you need to edit HTML parts, such as the title and stylesheet link tags.
I'm glad you find it useful.  _________________ Michael P.
 |
|
Back to top |
|
 |
Tanman
Joined: 28 Nov 2002 Posts: 36
|
Posted: Tue Jan 14, 2003 4:28 am Post subject: |
|
|
Hi Mike,
Is it possible to copy just the "new archive" for the blog?
I sort of want to keep the default layout for b2.
Can you please post up or highlight the code for the b2archive code only. The one you have is there seems to have the whole html page.
Thanks once again.  |
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1278 Location: Oregon
|
Posted: Tue Jan 14, 2003 4:51 am Post subject: |
|
|
I was unable to highlight them, because of the "code" tags. Sorry.
Basically, you have to replace anything between the following:
Code: |
<?php if ($showall==1) { ?>
|
And here goes HTML...
There are 2 HTML sections, one on the top and another on the bottom. Sorry I couldn't be more of a help. _________________ Michael P.
 |
|
Back to top |
|
 |
Tanman
Joined: 28 Nov 2002 Posts: 36
|
Posted: Wed Jan 15, 2003 4:32 am Post subject: |
|
|
Thanks,
all sorted
much appreciated  |
|
Back to top |
|
 |
beachgerl
Joined: 14 Apr 2003 Posts: 37 Location: San Diego
|
Posted: Wed Sep 10, 2003 6:27 am Post subject: |
|
|
Hi Cyberian --
Thanks for directing me to this thread. Just what I'm looking for. I got a parse error when using this hack you generously provided. It said parse error on line 3. I'm not sure what exactly did I do wrong? I hate those parse errors! I just copied and pasted your code onto text editor. Here's the code:
Code: |
<?php
if (!isset($showall)) {
$showall = 0;
}
if ($showall == 1) { ?>
//start editing
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" />
<html lang="en-us">
<head>
<title>All Archives</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="/slcss.css" type="text/css" />
</head>
<body>
<h3>All Archives</h3>
//stop editing
<?php } ?>
<?php
// *** b2 Archive file
require_once('./b2config.php');
require_once($b2inc.'/b2functions.php');
dbconnect();
function count_month_posts($year, $month) {
global $tableposts;
$count = mysql_query("SELECT COUNT(*) FROM $tableposts WHERE (YEAR(post_date) = '$year' AND MONTH(post_date) = '$month')");
$count = mysql_result($count,0);
return $count;
}
// this is what will separate your archive links
$archive_line_separator = '<br />';
// this is what will separate dates on weekly archive links
$archive_week_separator = ' - ';
// archive link url
$archive_link_m = $siteurl/'.$blogfilename.'?m='; # monthly archive
$archive_link_w = $siteurl/'.$blogfilename.'?w='; # weekly archive
$archive_link_p = $siteurl/'.$blogfilename.'?p='; # post-by-post archive
// over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
$archive_date_format_over_ride = 0;
// options for daily archive (only if you over-ride the general date format)
$archive_day_date_format = 'Y/m/d';
// options for weekly archive (only if you over-ride the general date format)
$archive_week_start_date_format = 'Y/m/d';
$archive_week_end_date_format = 'Y/m/d';
// --- //
$dateformat=get_settings('date_format');
$time_difference=get_settings('time_difference');
if (!$archive_date_format_over_ride) {
$archive_day_date_format = $dateformat;
$archive_week_start_date_format = $dateformat;
$archive_week_end_date_format = $dateformat;
}
if (basename($HTTP_SERVER_VARS['SCRIPT_FILENAME']) == 'b2archives.php')
include ('blog.header.php');
if (!isset($querycount)) {
$querycount = 0;
}
$now = date('Y-m-d H:i:s',(time() + ($time_difference * 3600)));
//begin 'more' hack
$arc_limit = 4; //define the number of months to display when included
$loopbr = 0;
//end 'more' hack
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++;
$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 $archive_line_separator."\n";
//begin 'more' hack
$loopbr++;
if ($showall == 0 && $loopbr == $arc_limit) {
break;
}
//end 'more' hack
}
//begin 'more' hack
if ($showall == 0 && $arc_limit < $arcnum_result) {
$arcnum_diff = $arcnum_result - $arc_limit;
echo '<br />(<a href="/b2archives.php?showall=1">'.$arcnum_diff.' More...</a>)';
}
//end 'more' hack
} elseif ($archive_mode == 'daily') {
$arc_sql="SELECT DISTINCT YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) FROM $tableposts WHERE post_date < '$now' AND post_category > 0 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)'];
$arc_dayofmonth = $arc_row['DAYOFMONTH(post_date)'];
echo "<a href=\"$archive_link_m$arc_year".zeroise($arc_month,2).zeroise($arc_dayofmonth,2).'">';
echo mysql2date($archive_day_date_format, $arc_year.'-'.zeroise($arc_month,2).'-'.zeroise($arc_dayofmonth,2).' 00:00:00');
# echo $month[zeroise($arc_month,2)]." $arc_year";
echo '</a>';
echo $archive_line_separator."\n";
}
} 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++;
$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 $archive_line_separator."\n";
}
}
} elseif ($archive_mode == 'postbypost') {
$requestarc = " SELECT ID,post_date,post_title FROM $tableposts WHERE post_date < '$now' AND post_category > 0 ORDER BY post_date DESC";
$querycount++;
$resultarc = mysql_query($requestarc);
while($row=mysql_fetch_object($resultarc)) {
if ($row->post_date != '0000-00-00 00:00:00') {
echo "<a href=\"$archive_link_p".$row->ID.'">';
$arc_title = stripslashes($row->post_title);
if ($arc_title) {
echo strip_tags($arc_title);
} else {
echo $row->ID;
}
echo '</a>';
echo $archive_line_separator."\n";
}
}
}
#echo $querycount."<br />\n";
#timer_stop(1,8);
if ($showall == 1) { ?>
//start editing
<br /><br /><br />
<span style="color: #FFFFCC">::</span> <a href="javascript:history.go(-1);">Return to the previous screen</a>
</body>
</html>
//stop editing
<?php } ?> |
Thanks. _________________
|
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1278 Location: Oregon
|
Posted: Wed Sep 10, 2003 4:27 pm Post subject: |
|
|
Can you post the error? _________________ Michael P.
 |
|
Back to top |
|
 |
beachgerl
Joined: 14 Apr 2003 Posts: 37 Location: San Diego
|
Posted: Wed Sep 10, 2003 8:15 pm Post subject: |
|
|
The error msg said:
"Parse error /www/domain/index.php, on line 3" _________________
|
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1278 Location: Oregon
|
Posted: Wed Sep 10, 2003 10:42 pm Post subject: |
|
|
The error is in your index file then, not the archive file.
You have to copy and paste it into b2archives.php file. You basically replace it with my code. _________________ Michael P.
 |
|
Back to top |
|
 |
beachgerl
Joined: 14 Apr 2003 Posts: 37 Location: San Diego
|
Posted: Thu Sep 11, 2003 12:46 am Post subject: |
|
|
Cyberian75 wrote: | The error is in your index file then, not the archive file.
You have to copy and paste it into b2archives.php file. You basically replace it with my code. |
Ok. I copied and pasted your code on b2archives.php file and that's when the parse error came up after uploading it. Was I supposed to edit the HTML part in my template or in b2archives.php file itself? Are HTML and code together or separate? I had to double-check before getting confused. Do I need to modify the b2archives.php tag in my template to be able to read from b2archives.php file? Thanks. _________________
|
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1278 Location: Oregon
|
Posted: Thu Sep 11, 2003 1:11 am Post subject: |
|
|
Ok, if you want to be able to rollback, I would suggest that you make a copy of the original file.
Anyway, copy and paste the code into the b2archives.php file, over-writing the original code. You can then include it normally in your template:
Code: |
<?php include("b2archives.php"); ?>
|
And you can edit the HTML sections of the code. _________________ Michael P.
 |
|
Back to top |
|
 |
|
|
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
|