部落格中添加日曆的php代碼_PHP教程

來源:互聯網
上載者:User

部落格中添加日曆的php代碼


  想不想在你得部落格中添加日曆啊?blue1000在這裡跟大家簡潔的分享一款PHP中部落格日曆實現代碼,有需要的朋友參考一下,裡面有一句是查詢資料庫的這個很簡單,你只要修改一下欄位名與你資料庫相同就行了。

  代碼如下:

  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;

  }

http://www.bkjia.com/PHPjc/847206.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/847206.htmlTechArticle部落格中添加日曆的php代碼 想不想在你得部落格中添加日曆啊?blue1000在這裡跟大家簡潔的分享一款PHP中部落格日曆實現代碼,有需要的朋友參考一...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.