08. เพิ่มส่วนแสดงเนื้อหาในหน้าหลัก (Generate a page content)
Submitted by wd on Wed, 2008-01-16 12:18
โค๊ดหลักมีแต่การแสดงเนื้อในบล๊อกซึ่งมีเนื้อที่จำกัด คราวนี้เรามาเพิ่มให้แสดงเนื้อในหน้าหลักได้ โดยเราสามารถแสดงได้ไม่จำกัดจำนวนหัวข้อ
ทำผ่านฟังก์ชั่น onthisdate_all()
<?php
function onthisdate_all() {
// content variable that will be returned for display
$page_content = '';
// Get today's date
$today = getdate();
// calculate midnight one week ago
$start_time = mktime(0, 0, 0, $today['mon'], ($today['mday'] - 7), $today['year']);
// we want items that occur only on the day in question,
// so calculate 1 day
$end_time = $start_time + 86400;
// 60 * 60 * 24 = 86400 seconds in a day
$query = "SELECT nid, title, created FROM " .
"{node} WHERE created >= '%d' " .
" AND created <= '%d'";
// get the links (no range limit here)
$queryResult = db_query($query, $start_time, $end_time);
while ($links = db_fetch_object($queryResult)) {
$page_content .= l($links->title, 'node/'.$links->nid).'<br />';
}
// check to see if there was any content before
// setting up the block
if ($page_content == '') {
// no content from a week ago, let the user know
$page_content = "No events occurred on this site on this date in history.";
}
return $page_content;
}
?>- ฟังก์ชั่น
onthisdate_allไม่ใช่ฮุก ถ้ามอดูลอื่นจะเรียกใช้ ต้องเรียกผ่านฟังก์ชั่นระบบmodule_invoke() - แต่ถ้าเราจะให้ฟังก์ชั่นของเราดูได้เฉพาะภายใน ต้องนำหน้าชื่อฟังก์ชั่นด้วยขีดเส้นใต้
_
- Printer-friendly version
- Log in or register to post comments
- 4472 reads







Recent comments