View previous topic :: View next topic |
Author |
Message |
Cyberian75
Joined: 26 Sep 2002 Posts: 1278 Location: Oregon
|
Posted: Sun Dec 07, 2003 1:40 am Post subject: [Function] Posts n Ago Today |
|
|
This function displays a link to your post(s) you wrote n days, months or years ago today.
Code: |
function agotoday($num=1, $type='year', $linkmsg='year ago today...') {
global $tableposts, $querycount, $siteurl;
$query = "SELECT YEAR(post_date) AS year, MONTH(post_date) AS month, DAYOFMONTH(post_date) AS day FROM $tableposts " .
"WHERE DATE_FORMAT(post_date, '%m-%d-%Y') = DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL '$num' $type), '%m-%d-%Y') " .
"ORDER BY post_date ASC LIMIT 1";
$result = mysql_query($query) or die(mysql_error());
$exist = mysql_num_rows($result);
$querycount++;
if ($exist) {
$row = mysql_fetch_object($result);
$year = $row->year;
$month = zeroise($row->month,2);
$day = zeroise($row->day,2);
echo '<a href="'.$siteurl.'/?m='.$year.$month.$day.'">'.$num.' '.$linkmsg.'</a>';
}
}
|
You can call it with...
Code: |
<?php agotoday(6, 'month', 'months ago today...'); ?>
|
The first parameter is the number of days, months or years specified as the second parameter and the last parameter is for the link.
Revised edition
This will produce titles of your post(s) you made n ago today, and they will be linked to individual post(s).
Code: |
function agotoday($num=3, $type='month', $linkmsg='months ago today...') {
global $tableposts, $querycount, $siteurl;
$query = "SELECT YEAR(post_date) AS year, MONTH(post_date) AS month, DAYOFMONTH(post_date) AS day FROM $tableposts " .
"WHERE DATE_FORMAT(post_date, '%m-%d-%Y') = DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL '$num' $type), '%m-%d-%Y') " .
"ORDER BY post_date DESC LIMIT 1";
$result = mysql_query($query) or die(mysql_error());
$exist = mysql_num_rows($result);
$querycount++;
if ($exist) {
$row = mysql_fetch_object($result);
$year = $row->year;
$month = $row->month;
$day = $row->day;
echo $num.' '.$linkmsg.'<br />';
$querytitles = "SELECT ID, post_title FROM $tableposts WHERE '$year' = YEAR(post_date) AND '$month' = MONTH(post_date) AND '$day' = DAYOFMONTH(post_date)";
$results = mysql_query($querytitles) or die(mysql_error());
$querycount++;
while($rows = mysql_fetch_array($results)) {
echo '<a href="'.$siteurl.'/?p='.$rows["ID"].'">'.$rows["post_title"].'</a><br />';
}
echo '<br />';
}
}
|
_________________ Michael P.

Last edited by Cyberian75 on Wed Dec 31, 2003 1:23 am; edited 16 times in total |
|
Back to top |
|
 |
epolady
Joined: 30 Jul 2002 Posts: 800 Location: Texas
|
Posted: Sun Dec 07, 2003 1:54 am Post subject: |
|
|
Ahhhhhhhh, very cool (saw it in your blog). Good job again, as always. _________________ No more support from me. Goodbye!
Go upgrade to WordPress, you'll find better support there. |
|
Back to top |
|
 |
ghost0156
Joined: 19 Nov 2003 Posts: 28
|
Posted: Mon Dec 08, 2003 9:29 pm Post subject: |
|
|
im not understand please! |
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1278 Location: Oregon
|
Posted: Mon Dec 08, 2003 9:36 pm Post subject: |
|
|
What don't you understand??? _________________ Michael P.
 |
|
Back to top |
|
 |
jackiefg
Joined: 15 Oct 2003 Posts: 29 Location: Toronto, Ontario, Canada
|
Posted: Tue Dec 30, 2003 2:07 am Post subject: Ok, what am I doing wrong? |
|
|
I pasted the top code into a file by itself called agotoday.php.
Then I copied and pasted the call function into my page and I got the following error message:
Fatal error: Call to undefined function: agotoday() in /hsphere/local/home/jackiefg/jackiefg.com/blog/indextest.php on line 257
What am I doing wrong here? pleeeeeeease. _________________ jackiefg |
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1278 Location: Oregon
|
Posted: Tue Dec 30, 2003 2:47 am Post subject: |
|
|
Jackie,
Looks like you forgot to "include" that file from one of the b2 files. I suggest including it at the end of "b2template.functions.php" file right before "?>".
Code: |
include("agotoday.php");
|
_________________ Michael P.
 |
|
Back to top |
|
 |
jackiefg
Joined: 15 Oct 2003 Posts: 29 Location: Toronto, Ontario, Canada
|
Posted: Tue Dec 30, 2003 4:05 am Post subject: I'm still doing something wrong. |
|
|
Thanks Cyberian, I've included the include in my b2template.functions file. It now does not give me the error message but instead it just shows me "2 months ago today..." and nothing else.
Shouldn't it show something I wrote 2 months ago today? Does it have to do with the b2template.functions file being in a subdirectory called b2-include?
Do I need to put in an absolute path or something? Real brain power happening here as you can see.
Thanks for your help _________________ jackiefg |
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1278 Location: Oregon
|
Posted: Tue Dec 30, 2003 4:13 am Post subject: |
|
|
It's only supposed to spit out a link to your post(s) you made n days/months/years ago. I suggest you to call several instances of it with different parameters. _________________ Michael P.
 |
|
Back to top |
|
 |
zangerbanger
Joined: 22 Jun 2003 Posts: 18 Location: Canada
|
Posted: Tue Dec 30, 2003 4:46 am Post subject: |
|
|
Great hack ! |
|
Back to top |
|
 |
jackiefg
Joined: 15 Oct 2003 Posts: 29 Location: Toronto, Ontario, Canada
|
Posted: Tue Dec 30, 2003 5:00 am Post subject: There's no link |
|
|
It just shows me "2 months ago today..." but it is not linked to anything and it doesn't show text or a link. Am I missing something? _________________ jackiefg |
|
Back to top |
|
 |
epolady
Joined: 30 Jul 2002 Posts: 800 Location: Texas
|
Posted: Tue Dec 30, 2003 5:27 am Post subject: |
|
|
Do you have a post from 2 months ago? If not, use something sooner than 2 months. _________________ No more support from me. Goodbye!
Go upgrade to WordPress, you'll find better support there. |
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1278 Location: Oregon
|
Posted: Tue Dec 30, 2003 6:43 am Post subject: |
|
|
Epolady is correct. If there were no post(s) n ago, there won't be any links.
I've modified the function so that it won't produce anything if there were no post(s).
 _________________ Michael P.
 |
|
Back to top |
|
 |
jackiefg
Joined: 15 Oct 2003 Posts: 29 Location: Toronto, Ontario, Canada
|
Posted: Tue Dec 30, 2003 3:51 pm Post subject: You're a genius! |
|
|
Ok, that's exactly it. Thank you, thank you. I looked back in my archives for two months ago and of course there were no posts on the 29th or 30th, so when I modified it to show one month, it worked - it linked *woohoo*.
As I look at that link, I wonder if there's a way to have it show "1 month ago today" and underneath it shows the title of the post, or the first 10 words or something.
Or is that a whole nother rewrite of the code? _________________ jackiefg |
|
Back to top |
|
 |
jackiefg
Joined: 15 Oct 2003 Posts: 29 Location: Toronto, Ontario, Canada
|
Posted: Tue Dec 30, 2003 5:10 pm Post subject: Ooops |
|
|
BTW, I had to take it out of b2template.functions because when I went to post, I had a function error on the b2 template. So I changed the include to be on the same page as my blog - include "agotoday" - I put it in the top of my blog page and it still worked that way. _________________ jackiefg |
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1278 Location: Oregon
|
Posted: Tue Dec 30, 2003 8:49 pm Post subject: |
|
|
The following will display the title(s).
_________________ Michael P.

Last edited by Cyberian75 on Wed Dec 31, 2003 12:52 am; edited 1 time in total |
|
Back to top |
|
 |
|