Diz 論壇的資料呼叫有 2 種模式。一種是內部呼叫,在模板中嵌入呼叫程式碼,一種是外部呼叫,在網頁中嵌入 js 程式碼。外部呼叫無法生成靜態程式碼,只有依靠內部呼叫,才能生成具體內容。
第一步,在 diz 論壇的系統目錄下建立一個檔案,例如叫 test.php,內容很簡單:
<?php
require_once './include/common.inc.php';//相對路徑要正確
include template('test');//載入模板檔案,模板檔名為 test.htm
?>
第二步,在 templates/default 目錄下建立檔案 test.htm,主要內容如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta content="text/html; charset=gb2312" http-equiv="content-type" />
<link type="text/css" rel="stylesheet" href="http://weixiaoduo.com/s.css" />
<title> 薇曉朵</title>
<base href="https://www.weixiaoduo.com/bbs/" />
<!--如果 test.php 和 diz 安裝目錄不在同一目錄,此處 「base href=……」 語句不可少 -->
</head>
<body style="text-align: center" >
{eval request('主題列表_八卦');}<!-----嵌入內部呼叫,換成自己的---
</body>
</html>
現在就可以直接執行 test.php 了!並且瀏覽器的網頁中能看到具體的內容,而不是 js 程式碼。
第三步:如果需要生成 html 靜態檔案,則需另寫一個檔案 test1.php,內容如下:
<?php
$bruce=fopen("https://www.weixiaoduo.com/bbs/test.php","r");//你的 test.php 的網址
if(!$bruce)
{ echo'檔案不存在';
exit;
}
while (!feof($bruce))
{
$rose=fgets($bruce);
$james=fopen("index.html","a");//index.html 為將生成的靜態 html 網頁的地址和名字
fwrite($james,$rose);
}
fclose($bruce);
?>
<a href="index.html"> 點選檢視生成的檔案</a>
在瀏覽器中開啟 test1.php,執行程式碼,到這裡,靜態網頁,基本完成了。
什麼時候生成靜態網頁?多久生成一次靜態網頁,希望大家一起來想辦法。