TinyPortal

Development => Block Codes => Topic started by: fangweile on September 18, 2008, 04:32:44 AM

Title: [Block] Display articles on anniversary of creation date
Post by: fangweile on September 18, 2008, 04:32:44 AM
Would it be possible to display in a block the article within its creation date.

For example I created an article September 15, 2007 and when September 15, 2008 comes articles made in that date will displayed .

Any idea.

Thanks in advance.
Title: Re: Display article in creation date
Post by: JPDeni on September 18, 2008, 02:53:06 PM
I'm sure it can be done. I'm just not sure of the syntax for the query to translate the timestamp. I'll do some looking to see if I can find it. I'm just about positive that there is one. It's just not something I've used before.

ETA:

Okay. I got it. Sorta.  :) You want a block with a list of articles where the anniversary of the creation date is today. Yes?

One problem is the definition of "today." I think that, if we just go by the stored date, we'll get GMT. Either that or server time. I'm never quite sure. At any rate, it may not be the same time zone as the user who is looking at it or the actual date, from the perspective of the creator, that it was created. So the dates could be off one day.

The second problem is that I don't know how you want them listed. Just titles with a link?

So I don't lose track of the code I worked out, I'll put it here.



$today = date('-m-d');

WHERE FROM_UNIXTIME(date) LIKE '%" . $today . "%'

Title: Re: Display article in creation date
Post by: fangweile on September 19, 2008, 04:49:18 AM
Thanks a lot for your work JPDeni,

I just want to simply display the article title and its links. ^_^

Title: Re: Display article in creation date
Post by: JPDeni on September 19, 2008, 04:03:31 PM
Okay. :)



global $db_prefix, $scripturl;

$today = date('-m-d');

$query = db_query(
    "SELECT id, date, subject, shortname
     FROM {$db_prefix}tp_articles
     WHERE FROM_UNIXTIME(date) LIKE '%" . $today . "%'
     AND approved=1", __FILE__, __LINE__);
if(db_affected_rows() != 0)
{
  echo 'Articles added on this date: <br />';
  while ($row = mysql_fetch_assoc($query))
  {
    if(empty($row['shortname'])) $row['shortname'] = $row['id']; 
    echo '<a href="' . $scripturl . '?page=' . $row['shortname'] . '">' . $row['subject'] . '</a><br />';
  }
}
else {
  echo 'No articles were added on this date.';
}



Thanks to Iandres for reminding me about checking for whether the shortname has been set.
Title: Re: Display article in creation date
Post by: fangweile on September 21, 2008, 02:18:23 AM
OMG, Thanks a lot.
I works great.
I really appreciate your help.
Thanks again.
Title: Re: Display article in creation date
Post by: JPDeni on September 21, 2008, 02:24:33 AM
:) I'm glad it works for you. I'll move this over to the snippets forum.
Title: Re: [Block] Display articles on anniversary of creation date
Post by: fangweile on September 28, 2008, 12:08:53 PM
hello again,

I've noticed that my server time is different from my local time.

The article display September 28 while in my current time is September 29.
What code should I add to set the timezone in my current time?

Thanks again in advance.
Title: Re: [Block] Display articles on anniversary of creation date
Post by: G6Cad on September 28, 2008, 12:22:28 PM
The forum time is fetched from SMF, so your question is best asked over at simplemachines.org
Title: Re: [Block] Display articles on anniversary of creation date
Post by: IchBin on September 28, 2008, 08:47:26 PM
She is referring to the code G6. It would probably help Deni if you gave her exact details about how much time difference, and which time zone you are in so she can help you when she gets back. Right now, she's on a little vacation. Not sure when she plans to be back.
Title: Re: [Block] Display articles on anniversary of creation date
Post by: fangweile on September 29, 2008, 02:40:49 AM
Alright,
I've figured it out

I use this code

$today = date('-m-d', strtotime("+13 hours"));


Thanks a lot for your help  ;)
Title: Re: [Block] Display articles on anniversary of creation date
Post by: FERNSIDEâ„¢ on October 11, 2008, 09:25:15 PM
Hey this is great!!
Thanks peeps :)
Good stuff on figuring out the time diff prob yourself fangweile.