Home  >  Article  >  Backend Development  >  PHP code to add calendar to blog_PHP tutorial

PHP code to add calendar to blog_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:22:36840browse

PHP code for adding a calendar to your blog

Do you want to add a calendar to your blog? blue1000 is here to briefly share with you a blog calendar implementation code in PHP. Friends in need can refer to it. There is a sentence in it that querying the database is very simple. You only need to modify the field name to be the same as your database.

The code is as follows:

Function calendarnew($starttime = 0) {

global $db, $tablepre, $timestamp, $site_timeoffset, $site_dateformat, $curtime;

 $starttime = $starttime ? $starttime : $timestamp;

$curtime = gmdate($site_dateformat, $starttime + $timeoffset * 3600);

 $pendtime = $starttime - (gmdate('j', $starttime + $timeoffset * 3600) - 1) * 86400 - ($starttime + $timeoffset * 3600) % 86400;

 $pstarttime = $pendtime - gmdate('t', $pendtime + $timeoffset * 3600 - 1) * 86400;

 $nstarttime = $pendtime + gmdate('t', $pendtime + $timeoffset * 3600 + 1) * 86400;

 $nendtime = $nstarttime + gmdate('t', $nstarttime + $timeoffset * 3600 + 1) * 86400;

List($skip, $dim) = explode('-', gmdate('w-t', $pendtime + $timeoffset * 3600 + 1));

 $rows = ceil(($skip + $dim) / 7);

 $blogs = array();

$query = $db->query("SELECT dateline FROM {$tablepre}vitaitems WHERE dateline BETWEEN '$pendtime' AND '$nstarttime'");

while($blog = $db->fetch_array($query)) {

 $day = gmdate('j', $blog['dateline'] + $timeoffset * 3600);

 !isset($blogs[$day]) ? $blogs[$day] = array('num' => 1, 'dateline' => $blog['dateline'] - $blog['dateline '] % 86400): $blogs[$day]['num']++;

 }

$cal = '';

 for($row = 0; $row < $rows; $row++) {

$cal .= '';

 for($col = 0; $col < 7; $col++) {

 $cur = $row * 7 + $col - $skip + 1;

 $curtd = $row * 7 + $col < $skip || $cur > $dim ? ' ' : $cur;

 if(!isset($blogs[$cur])) {

$cal .= ''.$curtd.'';

 } else {

 $cal .= ''.$cur.'';

 }

 }

$cal .= '';

 }

return $cal;

 }

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/847206.htmlTechArticlePHP code for adding calendar to blog Do you want to add calendar to your blog? blue1000 is here to tell you briefly Share a blog calendar implementation code in PHP, friends in need can refer to it...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn