View previous topic :: View next topic |
Author |
Message |
alex_t_king
Joined: 09 Oct 2002 Posts: 194
|
Posted: Mon Nov 04, 2002 9:07 am Post subject: A couple of hacks... |
|
|
I've written a couple of hacks and made them available on my site. The top three were requested in the "How To" section of the forum.
- Set a cookie so that you can show your visitors which posts and comments are new since their last visit.
- Show previous/next arrows on the calendar.
- Show that day's post titles on mouseover of a day in the calendar.
- Show the number of posts at the end of each category name: General (25)
- Show the number of posts at the end of each month name: November (2)
(this only works in monthly archive mode)
If you find any problems, bugs, hidden dependencies, etc. trying to use these - let me know. _________________ Yahoo! Messenger ID: alex_t_king |
|
Back to top |
|
 |
GamerZ
Joined: 15 May 2002 Posts: 537 Location: Singapore
|
Posted: Mon Nov 04, 2002 10:01 am Post subject: |
|
|
erm i got 1 bug regarding the last visit hack
here is the problem
Let say user visit my page @ 12.35pm, he close the browser and later at maybe about 12.40pm.
He come in again, the last visit will display as 12.35pm, nothing wrong with that. He closes the browser again.
But when he came in for the 3rd time, the last visit shld display at 12.40pm but it display at 12.35pm.
Subsequently for the 4th, 5th visit the time is still at 12.35pm. _________________
++ GamerZ.Per.Sg - Complex Simplicity |
|
Back to top |
|
 |
alex_t_king
Joined: 09 Oct 2002 Posts: 194
|
Posted: Mon Nov 04, 2002 10:23 am Post subject: |
|
|
hmm, I don't have that problem on my site... tested in Mozilla and IE. Make sure you hit refresh so it isn't pulling the page from cache. I've set it to always show on my site so you can test it - take a look and see if you see it working properly on my site. _________________ Yahoo! Messenger ID: alex_t_king |
|
Back to top |
|
 |
alex_t_king
Joined: 09 Oct 2002 Posts: 194
|
Posted: Mon Nov 04, 2002 11:30 am Post subject: |
|
|
I had forgotten to include some instructions in the zip file, specifically the code to set the cookie. If you removed the code to set the cookie (from the old version) then it would explain why the cookie wasn't changing. That code is still needed. Grab an updated zip file or read the notes I added on the page and you should be all set.
Thanks. _________________ Yahoo! Messenger ID: alex_t_king |
|
Back to top |
|
 |
GamerZ
Joined: 15 May 2002 Posts: 537 Location: Singapore
|
Posted: Mon Nov 04, 2002 3:07 pm Post subject: |
|
|
erm
u forgot to get $post_id _________________
++ GamerZ.Per.Sg - Complex Simplicity |
|
Back to top |
|
 |
alex_t_king
Joined: 09 Oct 2002 Posts: 194
|
Posted: Mon Nov 04, 2002 6:10 pm Post subject: |
|
|
geesh - I'm bad at packaging these things.
Yes you can pass in the id of the post, somehow I zipped the wrong version of the ak_new_posts()/ak_new_comments() functions and it was required in that one. In the current version I've set the default of $post_id to -1 and then call the global $id (assuming we're in a loop). Funny, I got this all working just fine on my own site - from the way I've bungled trying to package these things I'm surprised the site it even running!
Thanks for the help GamerZ, hopefully that is the last of it. _________________ Yahoo! Messenger ID: alex_t_king |
|
Back to top |
|
 |
mikelittle
Joined: 11 May 2002 Posts: 376 Location: UK
|
Posted: Tue Nov 05, 2002 1:28 am Post subject: |
|
|
Alex,
I noticed on your site you mention "...but retaining the speedier SQL query I was using", with regard to the category count hack. However you are still using (1 + number of categories) queries. It can all be done with a single query which should be even faster.
[php:1:a6a2b227cd]<?php
// hack from http://www.adamwalker.34sp.com/index.php?p=37&more=1
function list_cats($optionall = 1, $all = 'All', $sort_column = 'cat_ID', $sort_order = 'asc',
$file = 'blah', $optiondates = 0, $optioncount = 0, $hide_empty = 1) {
global $tablecategories,$querycount, $tableposts;
global $pagenow;
global $querystring_start, $querystring_equal, $querystring_separator;
$file = ($file == 'blah') ? $pagenow : $file;
$sort_column = 'cat_'.$sort_column;
$query = " SELECT cat_ID, cat_name,";
$query .= " count(b2posts.ID) AS cat_count,";
$query .= " DAYOFMONTH(MAX(post_date)) AS lastday, MONTH(MAX(post_date)) AS lastmonth";
$query .= " FROM $tablecategories LEFT JOIN $tableposts ON cat_ID = post_category";
$query .= " WHERE cat_ID > 0 ";
$query .= " GROUP BY post_category ";
if (intval($hide_empty) == 1) {
$query .= " HAVING cat_count > 0";
}
$query .= " ORDER BY $sort_column $sort_order, post_date DESC";
$result=mysql_query($query); // or die("Couldn't execute query $query ". mysql_error());
$querycount++;
if (intval($optionall) == 1) {
echo "\t<a href=\"".$file.$querystring_start.'cat'.$querystring_equal.'all">'.$all."</a><br />\n";
}
while($row = mysql_fetch_object($result)) {
echo "\t<a href=\"".$file.$querystring_start.'cat'.$querystring_equal.$row->cat_ID.'">';
echo stripslashes($row->cat_name)."</a>";
if (intval($optioncount) == 1) {
echo " (".$row->cat_count.")";
}
if (intval($optiondates) == 1) {
echo " ".$row->lastday."/".$row->lastmonth."";
}
echo "<br />\n";
}
}
[/php:1:a6a2b227cd]
Note this is a hack of the original list_cats() and includes the optional date of last post in category. I've added in your hide_empty flag.
Also my archive count of posts here also works for weeks as well as months.
Mike[url][/url] |
|
Back to top |
|
 |
alex_t_king
Joined: 09 Oct 2002 Posts: 194
|
Posted: Tue Nov 05, 2002 3:44 am Post subject: |
|
|
Very cool - good stuff Mike! _________________ Yahoo! Messenger ID: alex_t_king |
|
Back to top |
|
 |
GamerZ
Joined: 15 May 2002 Posts: 537 Location: Singapore
|
Posted: Tue Nov 05, 2002 3:57 am Post subject: |
|
|
my web server currently down could not ttest it out
and how come my cookie gives me the date 1970?
BTW do u require the function file first or set teh cookie first? _________________
++ GamerZ.Per.Sg - Complex Simplicity |
|
Back to top |
|
 |
alex_t_king
Joined: 09 Oct 2002 Posts: 194
|
Posted: Tue Nov 05, 2002 4:39 am Post subject: |
|
|
It doesn't matter which is first, the cookie has to be set before the HTML is passed to the browser, but the functions just need to be included before they called.
As for 1970 - I'm using unix timestamps when comparing the dates, it defaults to 1970. Not sure where that is coming from though, if there is no cookie set (and it should be set to a recent date) then it shouldn't show the string at all... _________________ Yahoo! Messenger ID: alex_t_king |
|
Back to top |
|
 |
GamerZ
Joined: 15 May 2002 Posts: 537 Location: Singapore
|
Posted: Tue Nov 05, 2002 7:23 am Post subject: |
|
|
okie got eveythign to work except 1 which is the ak_new_comments(), i put that in b2comments.php there is an mysql error where as the ak_new_post is put on index.php no error _________________
++ GamerZ.Per.Sg - Complex Simplicity |
|
Back to top |
|
 |
alex_t_king
Joined: 09 Oct 2002 Posts: 194
|
Posted: Tue Nov 05, 2002 9:24 am Post subject: |
|
|
hmm, yeah - like it says, it expects to be called from within the b2 loop, I haven't tested it elsewhere although it should work assuming the post id is set already or is passed in. I'm guessing that the post id isn't available... what is the mysql error? _________________ Yahoo! Messenger ID: alex_t_king |
|
Back to top |
|
 |
alex_t_king
Joined: 09 Oct 2002 Posts: 194
|
Posted: Tue Nov 05, 2002 5:28 pm Post subject: |
|
|
Another throught - perhaps $tableposts is not defined there? I'm not using b2comments on my site so I haven't played with it at all... _________________ Yahoo! Messenger ID: alex_t_king |
|
Back to top |
|
 |
MiniSizeIt
Joined: 02 Nov 2002 Posts: 70
|
Posted: Tue Nov 05, 2002 9:31 pm Post subject: |
|
|
Yea the comments also gives me a MySQL error. |
|
Back to top |
|
 |
alex_t_king
Joined: 09 Oct 2002 Posts: 194
|
Posted: Tue Nov 05, 2002 10:05 pm Post subject: |
|
|
What is the error and where are you calling the function? are you calling it from within the b2 post loop? _________________ Yahoo! Messenger ID: alex_t_king |
|
Back to top |
|
 |
|