View previous topic :: View next topic |
Author |
Message |
Cyberian75
Joined: 26 Sep 2002 Posts: 1100 Location: Oregon
|
Posted: Sat Jan 25, 2003 7:59 pm Post subject: Latest n Comments -- Rev. 0.5.0 |
|
|
I have written a function from scratch that will display a number of comments on your template. You can define the number of comments, the length of the contents, which will be replaced by a string you specify, and whether to show the comment date/time or not.
To call this function, use the following syntax:
Code: |
<?php latestcomments(5, 20, " said...", "[...]", 1, 1, 0); ?>
|
The first parameter is the number of comments that will be displayed; second parameter is the length of contents of comments; third parameter is what will appear after the name of the author; fourth parameter is what will be replaced with if the content is longer then you specified; the next two parameters will display the date and/or time if set to 1; and set the last parameter to 1 if you want comments in a popup window when the link is clicked.
If you leave all those parameters, defaults will be used. However, if you do put those parameters, make sure not to mix them up. And if you want to skip a parameter, skip it by leaving it empty but keep the sequence they are passed.
This cannot be used inside the b2 loop.
Save the following function in a separate file and call it from b2template_functions.php, or just copy and paste the function into that file. I recommend putting it in a separate file, preferably "latestcomments.php".
Updates:
---
0.5: A popup option added.
0.4.8: HTML tags are now stripped.
0.4.7: "Time-only" is now supported.
0.4.6: Added a check to see if the author URL is empty or not.
0.4.5: You can now define strings to be excluded from displaying.
0.4.3: Time is now supported.
0.4: A minor bug fixed.
---
You can see it working here.
You can get the code here.
Hope this would be useful to someone.  _________________ Michael P.
Last edited by Cyberian75 on Wed Oct 13, 2004 11:31 pm; edited 23 times in total |
|
Back to top |
|
 |
GamerZ
Joined: 15 May 2002 Posts: 537 Location: Singapore
|
Posted: Sun Jan 26, 2003 6:02 am Post subject: |
|
|
wow, nice job _________________
++ GamerZ.Per.Sg - Complex Simplicity |
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1100 Location: Oregon
|
Posted: Sun Jan 26, 2003 7:01 am Post subject: |
|
|
Thanks.
I need your help, though. For some reason, if I set the date variable $show_date to 0 and the time variable $show_time to 1, the time won't show. Any ideas why? _________________ Michael P. |
|
Back to top |
|
 |
GamerZ
Joined: 15 May 2002 Posts: 537 Location: Singapore
|
Posted: Wed Jan 29, 2003 5:38 pm Post subject: |
|
|
Cyberian75 wrote: | Thanks.
I need your help, though. For some reason, if I set the date variable $show_date to 0 and the time variable $show_time to 1, the time won't show. Any ideas why? | hmm, i am not too good in mysql LOL. For me i use DATE_FORMAT(post_date, '%e.%c.%Y @ %H:%i') and print out using array[1] instead of like array["date"] _________________
++ GamerZ.Per.Sg - Complex Simplicity |
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1100 Location: Oregon
|
Posted: Wed Jan 29, 2003 5:51 pm Post subject: |
|
|
Well, I'm trying to separate those two--date and time. Even if I use DATE_FORMAT function for the time, it returns a null value for some reason.  _________________ Michael P. |
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1100 Location: Oregon
|
Posted: Wed Jan 29, 2003 8:05 pm Post subject: |
|
|
I took a different approach and used the following:
Code: |
if ($show_datetime == 1) {
$joinquery .= ", DATE_FORMAT(comment_date, '%b. %D, %Y') AS commentdatetime ";
}
if ($show_datetime == 2) {
$joinquery .= ", DATE_FORMAT(comment_date, '@ %l:%i %p') AS commentdatetime ";
}
if ($show_datetime == 3) {
$joinquery .= ", DATE_FORMAT(comment_date, '%b. %D, %Y @ %l:%i %p') AS commentdatetime ";
}
|
The rest of the function changed accordingly, of course. However, the second and third statements return a null value no matter what I do.
Any ideas? _________________ Michael P. |
|
Back to top |
|
 |
blog17
Joined: 28 Jan 2003 Posts: 144 Location: London, UK
|
Posted: Thu Jan 30, 2003 2:40 am Post subject: @ ... ? |
|
|
Quote: | Michael said...
The "latest n comments" hack has been updated
...more >>
on Jan. 29th, 2003 @
|
Um... can you see the prob there? @ what?
Help?  _________________ Check this out! The ULTIMATE site! |
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1100 Location: Oregon
|
Posted: Thu Jan 30, 2003 3:11 am Post subject: |
|
|
It's been fixed. Time now works.
However, the odd behavior is still there; i.e., time-only mode is not working, meaning if you set $show_date to 0 and $show_time to 1, neither of them are displayed.
If you can figure it out, it would be very appreciated.
By the way, the new feature allows you to exclude strings that you define for $excludearray variable. I implemented this to exclude smilie characters from the comments. _________________ Michael P. |
|
Back to top |
|
 |
blog17
Joined: 28 Jan 2003 Posts: 144 Location: London, UK
|
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1100 Location: Oregon
|
Posted: Fri Feb 07, 2003 6:24 pm Post subject: |
|
|
Updated
Update History:
---
0.4.7: "Time-only" is now supported.
0.4.6: Added a check to see if the author URL is empty or too short.
0.4.5: You can now define strings to be excluded from displaying.
0.4.3: Time is now supported.
0.4: A minor bug fixed.
--- _________________ Michael P. |
|
Back to top |
|
 |
blog17
Joined: 28 Jan 2003 Posts: 144 Location: London, UK
|
Posted: Sun Feb 09, 2003 3:56 am Post subject: Fix |
|
|
If someone were to put a ' or a "" in the name field... you would get a slash / when it appears in the comments block. It would be great if this were fixed. _________________ Check this out! The ULTIMATE site! |
|
Back to top |
|
 |
bigsimon
Joined: 04 Jan 2003 Posts: 13
|
Posted: Tue Feb 11, 2003 12:39 am Post subject: |
|
|
I'm sort of a PHP newb...
How do I "call it from b2template.functions.php"? _________________ bigSimon |
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1100 Location: Oregon
|
Posted: Wed Feb 19, 2003 8:38 pm Post subject: |
|
|
Blog17, that's been fixed. You only needed to use the "stripslashes" function where you pull out the data from the database. Look within the while loop.
And Simon, you can "include" a file by putting the following code in the file where you want to include a file in:
Code: |
<?php include("filename.php"); ?>
|
To include something in b2template_functions.php, however, you would put the following just before the closing tag "?>":
Code: |
include("filename.php");
|
_________________ Michael P.
Last edited by Cyberian75 on Sun Oct 26, 2003 10:03 pm; edited 1 time in total |
|
Back to top |
|
 |
bigsimon
Joined: 04 Jan 2003 Posts: 13
|
|
Back to top |
|
 |
turtelina
Joined: 25 Jan 2002 Posts: 40 Location: Austria
|
Posted: Fri Mar 14, 2003 11:56 am Post subject: |
|
|
I love it Michael, it´s brilliant!
me hearts hacks  |
|
Back to top |
|
 |
|