boardom Forum Index boardom
b2 message board
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[Function] Posts n Ago Today
Goto page 1, 2  Next
 
Post new topic   Reply to topic    boardom Forum Index -> Hacks
View previous topic :: View next topic  
Author Message
Cyberian75



Joined: 26 Sep 2002
Posts: 1278
Location: Oregon

PostPosted: Sun Dec 07, 2003 1:40 am    Post subject: [Function] Posts n Ago Today Reply with quote

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
View user's profile Send private message AIM Address
epolady



Joined: 30 Jul 2002
Posts: 800
Location: Texas

PostPosted: Sun Dec 07, 2003 1:54 am    Post subject: Reply with quote

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
View user's profile Send private message
ghost0156



Joined: 19 Nov 2003
Posts: 28

PostPosted: Mon Dec 08, 2003 9:29 pm    Post subject: Reply with quote

im not understand please!
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Cyberian75



Joined: 26 Sep 2002
Posts: 1278
Location: Oregon

PostPosted: Mon Dec 08, 2003 9:36 pm    Post subject: Reply with quote

What don't you understand???
_________________
Michael P.

Back to top
View user's profile Send private message AIM Address
jackiefg



Joined: 15 Oct 2003
Posts: 29
Location: Toronto, Ontario, Canada

PostPosted: Tue Dec 30, 2003 2:07 am    Post subject: Ok, what am I doing wrong? Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Cyberian75



Joined: 26 Sep 2002
Posts: 1278
Location: Oregon

PostPosted: Tue Dec 30, 2003 2:47 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
jackiefg



Joined: 15 Oct 2003
Posts: 29
Location: Toronto, Ontario, Canada

PostPosted: Tue Dec 30, 2003 4:05 am    Post subject: I'm still doing something wrong. Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Cyberian75



Joined: 26 Sep 2002
Posts: 1278
Location: Oregon

PostPosted: Tue Dec 30, 2003 4:13 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
zangerbanger



Joined: 22 Jun 2003
Posts: 18
Location: Canada

PostPosted: Tue Dec 30, 2003 4:46 am    Post subject: Reply with quote

Great hack Smile !
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
jackiefg



Joined: 15 Oct 2003
Posts: 29
Location: Toronto, Ontario, Canada

PostPosted: Tue Dec 30, 2003 5:00 am    Post subject: There's no link Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
epolady



Joined: 30 Jul 2002
Posts: 800
Location: Texas

PostPosted: Tue Dec 30, 2003 5:27 am    Post subject: Reply with quote

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
View user's profile Send private message
Cyberian75



Joined: 26 Sep 2002
Posts: 1278
Location: Oregon

PostPosted: Tue Dec 30, 2003 6:43 am    Post subject: Reply with quote

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).

Smile
_________________
Michael P.

Back to top
View user's profile Send private message AIM Address
jackiefg



Joined: 15 Oct 2003
Posts: 29
Location: Toronto, Ontario, Canada

PostPosted: Tue Dec 30, 2003 3:51 pm    Post subject: You're a genius! Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
jackiefg



Joined: 15 Oct 2003
Posts: 29
Location: Toronto, Ontario, Canada

PostPosted: Tue Dec 30, 2003 5:10 pm    Post subject: Ooops Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Cyberian75



Joined: 26 Sep 2002
Posts: 1278
Location: Oregon

PostPosted: Tue Dec 30, 2003 8:49 pm    Post subject: Reply with quote

The following will display the title(s). Smile

Code:

Deleted

_________________
Michael P.



Last edited by Cyberian75 on Wed Dec 31, 2003 12:52 am; edited 1 time in total
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    boardom Forum Index -> Hacks All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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