View previous topic :: View next topic |
Author |
Message |
Jason Velocity
Joined: 25 Jan 2002 Posts: 45 Location: C>Springs>CO
|
Posted: Mon Mar 04, 2002 6:19 am Post subject: Archives hack |
|
|
I thought I would move Dodo's archives hack over to the forums for full disection.
http://cafelog.com/index.php?p=442&c=1#comments
here is the file
http://regretless.com/dodo/pure/b2/hacks/archives.zip
here are a couple of examples
http://regretless.com/dodo/pure/b2/b2archives.php
http://www.jasonvelocity.com/archives.php
First, I added the user nickname to the display
replace this:
Code: | $postdata = get_postdata2($row->ID);
echo $postdata["Date"];
echo " - <a href=\"$siteurl/".$blogfilename."?p=".$row->ID."&c=1"."\">";
if ($postdata["Title"]) {
$postdata["Title"] = stripslashes($postdata["Title"]);
echo $postdata["Title"];
} else {
echo $postdata["ID"];
}
echo "</a>";
echo "<br>\n"; |
With this:
Code: | $postdata = get_postdata2 ($row->ID);
$userinfo = get_userdata ($postdata["Author_ID"]);
echo $postdata["Date"];
echo " - <a href=\"$siteurl/".$blogfile."?p=".$row->ID."&c=1"."\">";
if ($postdata["Title"]) {
$postdata["Title"] = stripslashes($postdata["Title"]);
echo $postdata["Title"];
} else {
echo $postdata["ID"];
}
echo "</a> by ";
echo $userinfo["user_nickname"];
echo "<br>\n"; |
|
|
Back to top |
|
 |
Jason Velocity
Joined: 25 Jan 2002 Posts: 45 Location: C>Springs>CO
|
Posted: Mon Mar 04, 2002 7:36 am Post subject: Next - a better sort by author |
|
|
Next, I want to change the way is sorts and displays by author. what I'm trying to do will look something like this:
Author 1
post title
post title
post title
Author 2
post title
post title
post title
Any help would be appreciated. most people wouldn't find this useful, but I have around 20 users, so sorting this way would look real nice. |
|
Back to top |
|
 |
Benjy
Joined: 25 Jan 2002 Posts: 108 Location: Paris, France
|
Posted: Tue Mar 05, 2002 5:04 pm Post subject: |
|
|
This is perhaps the solution to your "problem", but as I don't have PHP nor FTP access where I actually am, I suggest to try this:
Replace
Code: | } elseif ($archive_mode == "postbypost") {
while($row=mysql_fetch_object($result)) {
$postdata = get_postdata2($row->ID);
$thismonth=mysql2date("Y\-m", $postdata["Date"]);
$linkmonth=mysql2date("Ym", $postdata["Date"]);
$i = "/".$thismonth."/";
if ($thismonth != $previousmonth) {
if (preg_match($i,$postdata["Date"])) {
echo "<br><a href=\"$siteurl/".$blogfilename."?m=$linkmonth\">";
echo $month[substr($thismonth,5,2)];
echo "</a>";
echo "<br>\n";
}
}
$previousmonth = $thismonth;
$postdata = get_postdata2($row->ID);
$userinfo = get_userdata ($postdata["Author_ID"]);
echo $postdata["Date"];
echo " - <a href=\"$siteurl/".$blogfilename."?p=".$row->ID."&c=1"."\">";
if ($postdata["Title"]) {
$postdata["Title"] = stripslashes($postdata["Title"]);
echo $postdata["Title"];
} else {
echo $postdata["ID"];
}
echo "</a> by ";
echo $userinfo["user_nickname"];
echo "<br>\n";
}
} |
With
Code: | } elseif ($archive_mode == "postbypost" && $way != "post_author") {
while($row=mysql_fetch_object($result)) {
$postdata = get_postdata2($row->ID);
$thismonth=mysql2date("Y\-m", $postdata["Date"]);
$linkmonth=mysql2date("Ym", $postdata["Date"]);
$i = "/".$thismonth."/";
if ($thismonth != $previousmonth) {
if (preg_match($i,$postdata["Date"])) {
echo "<br><a href=\"$siteurl/".$blogfilename."?m=$linkmonth\">";
echo $month[substr($thismonth,5,2)];
echo "</a>";
echo "<br>\n";
}
}
$previousmonth = $thismonth;
$postdata = get_postdata2($row->ID);
$userinfo = get_userdata ($postdata["Author_ID"]);
echo $postdata["Date"];
echo " - <a href=\"$siteurl/".$blogfilename."?p=".$row->ID."&c=1"."\">";
if ($postdata["Title"]) {
$postdata["Title"] = stripslashes($postdata["Title"]);
echo $postdata["Title"];
} else {
echo $postdata["ID"];
}
echo "</a> by ";
echo $userinfo["user_nickname"];
echo "<br>\n";
}
} elseif ($archive_mode == "postbypost" && $way == "post_author") {
while($row=mysql_fetch_object($result)) {
$postdata = get_postdata2($row->ID);
$userinfo = get_userdata($postdata["Author_ID"]);
$actual_user = $userinfo["user_nickname"];
if ($actual_user != $previous_user) {
echo $actual_user;
$previous_user = $actual_user;
}
echo "<a href=\"$siteurl/".$blogfilename."?p=".$row->ID."&c=1"."\">";
if ($postdata["Title"]) {
$postdata["Title"] = stripslashes($postdata["Title"]);
echo $postdata["Title"];
} else {
echo $postdata["ID"];
}
echo "</a>";
echo "<br>\n";
}
} |
Thx for telling me if it did work,
Benjy. |
|
Back to top |
|
 |
Jason Velocity
Joined: 25 Jan 2002 Posts: 45 Location: C>Springs>CO
|
Posted: Tue Mar 05, 2002 9:45 pm Post subject: Works! |
|
|
That solves the problem, but it is really slow. Let me tweak it a bit and see if I can get it to move faster, and add some cool formatting.
http://www.jasonvelocity.com/test.php
the odd part here is how it sorts. If you tell it to do descending, it will start with the person with the least posts, and end with me (who has the most posts)....pretty strange.
Next we should put the amount of post next to the authors name!. |
|
Back to top |
|
 |
Benjy
Joined: 25 Jan 2002 Posts: 108 Location: Paris, France
|
Posted: Tue Mar 05, 2002 11:20 pm Post subject: |
|
|
For the sorting, it's normal, because if you use a descending order for the dates, that means you'll have the latest (newest) date on top, and that's the same for the names, except the latest name is at the end of the alphabet
The only way to solve this, I think, would be to do another mysql request if $way="post_author"...
And I forgot the carriage return after the poster's name!
Benjy. |
|
Back to top |
|
 |
dodo
Joined: 25 Jan 2002 Posts: 35
|
Posted: Wed Mar 06, 2002 3:39 am Post subject: |
|
|
thanks for posting, i added the link to this thread in the read me file so others who need the modifcation can come and look =) _________________ http://pure-essence.net
b2 rocks |
|
Back to top |
|
 |
nessahead
Joined: 12 Mar 2002 Posts: 312 Location: Los Angeles, CA
|
Posted: Fri Apr 19, 2002 2:51 am Post subject: |
|
|
I love this hack =) One problem I'm having, though:
On the page I use to display this hack, I want to include a regular list of my archives (which happen to be monthly) in the sidebar. However, it's displaying the whole list of archives =/
Here's the code for my page:
Code: | <?php /* Don't remove this line, it calls the b2 function files ! */ $blog=1; include ("b2/blog.header.php"); ?>
<?php include("includes/header.php"); ?>
<p class="navtitle">full archive list</p>
<?php include("b2/b2archivesList.php"); ?>
<?php include("includes/sidebar.php"); ?>
<p class="navtitle">archives</p>
<?php include("b2/b2archives.php") ?>
<p><a href="/archivesList.php">Full Archive List</a></p>
<p class="navtitle">archive search</p>
<p align="center"><form name="searchform" method="get" action="<?php echo $PHP_SELF ?>">
<input type="text" name="s" size="15" /><br />
<img src="/images/1x1.gif" width="1" height="5"><br>
<input type="submit" name="submit" value="search" />
</form>
</p>
<p class="navtitle">recently updated b2 blogs</p>
<base target="_blank"><p><?php include("http://cafelog.com/changes.php"); ?></p>
<?php include("includes/footer.php"); ?> |
And here's what it looks like: http://www.nessahead.com/archivesListError.php
See how the sidebar's all screwy? The sidebar's supposed to look like this: http://www.nessahead.com
If anyone could help me out, I'd really appreciate it =)
Thanks! |
|
Back to top |
|
 |
mikelittle
Joined: 11 May 2002 Posts: 376 Location: UK
|
Posted: Sat May 11, 2002 1:22 am Post subject: Archives hack |
|
|
Nessa,
The reason your sidebar archives have changed is that Dodo's file is a replacement for the b2archives.php which is included in your side bar. The difference being that Dodo's version hard codes Code: | $archive_mode = "postbypost"; | into it.
It has a test Code: | if ($pagenow == "b2archives.php") | in there which is used to detect whether the include file is being displayed on its own (i.e. not an include). I guess this same test could be used to hard code the .
So you would replace:
Code: |
$pagenow = explode("/", $PHP_SELF);
$pagenow = trim($pagenow[(sizeof($pagenow)-1)]);
if ($pagenow == "b2archivesfull.php")
include ("blog.header.php");
if(!$way)
$way = "ID";
if(!$order)
$order = "DESC";
$archive_mode = "postbypost";
|
with:
Code: |
$pagenow = explode("/", $PHP_SELF);
$pagenow = trim($pagenow[(sizeof($pagenow)-1)]);
if ($pagenow == "b2archivesfull.php") {
include ("blog.header.php");
$archive_mode = "postbypost";
}
if(!$way)
$way = "ID";
if(!$order)
$order = "DESC";
|
I've not tested this but it may well do the trick.
Hope this helps,
Mike |
|
Back to top |
|
 |
nessahead
Joined: 12 Mar 2002 Posts: 312 Location: Los Angeles, CA
|
Posted: Sat May 11, 2002 1:31 am Post subject: |
|
|
I didn't really understand what you explained (sorry, I'm just not a PHP guru ) but I replaced the code you were talking about. Although it does fix the short archives list on the right, the Full Archive List in the content doesn't display any entries http://www.nessahead.com/archivesListError.php
Any ideas? It's not a huge deal, so don't worry about it if it's a big thing to go through Thanks for replying, though! _________________ raar! |
|
Back to top |
|
 |
mikelittle
Joined: 11 May 2002 Posts: 376 Location: UK
|
Posted: Sat May 11, 2002 1:48 am Post subject: |
|
|
Doh! I pasted the code from my version which is not called b2archives.php.
If you replace the b2archivesfull.php with b2archives.php that may fix it.
If not, I'll have to look at it some other day. Sorry :-(
It's nearly 2am here, and I must get some sleep :-)
Hope this helps
Mike |
|
Back to top |
|
 |
mikelittle
Joined: 11 May 2002 Posts: 376 Location: UK
|
Posted: Tue May 14, 2002 12:05 am Post subject: |
|
|
Nessa,
I've got it sorted. I've taken Dodo's original hack and moved his stuff into the latest (b2-0.6pre2-20020409) version of the b2archives.php include file.
So now it looks like this.
Code: |
<?php
// *** b2 Archive file
include ("./b2config.php");
// this is what will separate your archive links
$archive_separator = "<br />";
// 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
if (!isset($oldest_year)) {
// your oldest archives are from year...
$oldest_year = "2001";
}
// --- //
$pagenow = basename($PHP_SELF);
if ($pagenow == "b2archives.php") { // are we running standalone
include ("blog.header.php");
$archive_mode = "postbypost";
if(!$way)
$way = "ID";
if(!$order)
$order = "DESC";
//echo "Archives:";
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- layout credits goto http://bluerobot.com/web/layouts/layout2.html -->
<head>
<title><?php echo $blogname ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="reply-to" content="[email protected]" />
<meta http-equiv="imagetoolbar" content="no" />
<meta content="TRUE" name="MSSmartTagsPreventParsing" />
<style type="text/css" media="screen">
@import url( ../layout2b.css );
</style>
<link rel="stylesheet" type="text/css" media="print" href="b2-include/print.css" />
</head>
<body>
<h1><a href="index.php" title="<?php echo $blogname ?>">Back to <?php echo $blogname ?></a></h1>
<form action="<?=$PHP_SELF?>" method="post">
Order by
<select name="way">
<option value="ID" <?=($way == "ID") ? "SELECTED" : "" ?>>ID</option>
<option value="post_date" <?=($way == "post_date") ? "SELECTED" : "" ?>>date</option>
<option value="post_title" <?=($way == "post_title") ? "SELECTED" : "" ?>>title</option>
<option value="post_category" <?=($way == "post_category") ? "SELECTED" : "" ?>>category</option>
<option value="post_author" <?=($way == "post_author") ? "SELECTED" : "" ?>>author</option>
<!--
<option value="post_content">content</option>
<option value="post_karma">karma</option>
-->
</select>
<select name="order">
<option value="DESC" <?=($order == "DESC") ? "SELECTED" : "" ?>>Descending</option>
<option value="ASC" <?=($order == "ASC") ? "SELECTED" : "" ?>>Ascending</option>
</select>
<input type="submit" name="submit" value="sort" />
</form>
<?php } // end if standalone
if ($archive_mode == "monthly") {
for ($arc_year=date("Y"); $arc_year>=$oldest_year; $arc_year--) {
for ($arc_month=12; $arc_month>0; $arc_month--) {
$arc_sql="SELECT ID FROM $tableposts WHERE YEAR(post_date)='$arc_year' AND MONTH(post_date)='$arc_month' LIMIT 1";
$querycount++;
$arc_result=mysql_query($arc_sql);
if (mysql_num_rows($arc_result)) {
echo "<a href=\"$archive_link_m$arc_year".zeroise($arc_month,2)."\">";
echo $month[zeroise($arc_month,2)]." $arc_year";
echo "</a>";
echo $archive_separator."\n";
}
}
}
} elseif ($archive_mode == "weekly") {
for ($arc_year=date("Y"); $arc_year>=$oldest_year; $arc_year--) {
for ($arc_week=53; $arc_week>0; $arc_week--) {
$arc_sql="SELECT ID FROM $tableposts WHERE YEAR(post_date)='$arc_year' AND WEEK(post_date,$start_of_week)='$arc_week'";
$querycount++;
$arc_result=mysql_query($arc_sql);
if (mysql_num_rows($arc_result)) {
echo "<a href=\"$siteurl/".$blogfilename."?m=$arc_year&w=$arc_week\">";
echo "week #$arc_week - $arc_year";
echo "</a>";
echo $archive_separator."\n";
}
}
}
} elseif ($archive_mode == "postbypost") {
if ($pagenow == "b2archives.php") { // are we running standalone
$request = " SELECT * FROM $tableposts ORDER BY $way $order";
$result = mysql_query($request);
while($row=mysql_fetch_object($result)) {
$postdata = get_postdata2($row->ID);
$thismonth=mysql2date("Y\-m", $postdata["Date"]);
$linkmonth=mysql2date("Ym", $postdata["Date"]);
$i = "/".$thismonth."/";
if ($thismonth != $previousmonth) {
if (preg_match($i,$postdata["Date"])) {
echo "<br><a href=\"$siteurl/".$blogfilename."?m=$linkmonth\">";
echo $month[substr($thismonth,5,2)];
echo "</a>";
echo "<br>\n";
echo "<div id=\"content\">";
}
}
$previousmonth = $thismonth;
$postdata = get_postdata2 ($row->ID);
$userinfo = get_userdata ($postdata["Author_ID"]);
echo $postdata["Date"];
echo " - <a href=\"$siteurl/".$blogfile."?p=".$row->ID."&c=1"."\">";
if ($postdata["Title"]) {
$postdata["Title"] = stripslashes($postdata["Title"]);
echo $postdata["Title"];
} else {
echo $postdata["ID"];
}
echo "</a>";
//echo " by " + $userinfo["user_nickname"];
echo $archive_separator;
echo "</div>";
}
} else {
$requestarc = " SELECT ID,post_date,post_title FROM $tableposts 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."\">";
if (strip_tags($row->post_title)) {
echo strip_tags($row->post_title);
} else {
echo $row->ID;
}
echo "</a>";
echo $archive_separator."\n";
}
}
}
}
?>
|
This now works as an include file in the side bar, and as a standalone page. Plus if you set your archive_mode to postbypost in options, you still get the old behaviour in the side bar.
If you take a look at http://zed1.com/b2/ you can see the monthly archive in the RH Sidebar. Plus there is a link to full archives. This runs the same include file standalone and produces Dodo's hacked version.
It could probably do with some more work, but I think it will work for now.
Hope this helps,
Mike |
|
Back to top |
|
 |
nessahead
Joined: 12 Mar 2002 Posts: 312 Location: Los Angeles, CA
|
Posted: Tue May 14, 2002 6:52 am Post subject: |
|
|
Wow, amazing! Thank you so much, going to try it out right now  _________________ raar! |
|
Back to top |
|
 |
nessahead
Joined: 12 Mar 2002 Posts: 312 Location: Los Angeles, CA
|
Posted: Tue May 14, 2002 7:28 am Post subject: |
|
|
I set it up and it's working just fine!
I'm not sure how to go about making it match the rest of my site, though, since I'd need a footer and anything put after the "// end if standalone" ends up showing when i include it on the main page.
Here's the main page where it's included (yay!): http://www.nessahead.com
and here's the standalone: http://www.nessahead.com/b2/b2archives.php _________________ raar! |
|
Back to top |
|
 |
sven
Joined: 08 May 2002 Posts: 30 Location: Central Valley Cali
|
Posted: Thu May 16, 2002 5:15 am Post subject: How Do I Show Only a Specific Catagory? |
|
|
How do I display the archives of one specific catagory or NOT a specific catagory? Either one will work. _________________ <><sven><> |
|
Back to top |
|
 |
nessahead
Joined: 12 Mar 2002 Posts: 312 Location: Los Angeles, CA
|
Posted: Thu May 16, 2002 7:25 pm Post subject: |
|
|
In the url to your archives, you could do
Code: | http://www.whatever.com/blogurl.php?cat=1 |
or whatever category number you want.
What I did is replace
Code: | <?php /* Don't remove this line, it calls the b2 function files ! */ $blog=1; include ("b2/blog.header.php"); ?> |
with
Code: | <?php /* Don't remove this line, it calls the b2 function files ! */ $blog=1; $cat=1; include ("b2/blog.header.php"); ?> |
on my main index page when I wanted it to only display category 1. _________________ raar! |
|
Back to top |
|
 |
|