2013-09-27 17 views
0

我使用Kirby CMS並創建一個小片段,它通過帖子限制他們是什麼號碼,以及他們是什麼日期。一種基本上創建「autopost」系統的方法。php變量與網站寬範圍

$today = new DateTime("now"); //Declare today 
$startdate = new DateTime("2013-09-12"); //Declare startdate 
$interval = $startdate->diff($today); //Find the difference between startdate & today 
$latest = $interval->format('%a'); //Declare $latest variable to be that interval, formatted as integer 

所以我有它創建我的$latest變量,然後我就可以用它來控制所顯示的帖子點點。

我的問題是,我不想在每個不同類型的頁面模板上都更改我的$startdate,所以我想以某種方式使其在整個站點範圍內。

我試圖把它作爲一個片段與柯比的snippet()函數,但不起作用。我想,片段已經運行後,必須將片段帶入頁面。

如何讓我的代碼段適用於我的整個網站?

+0

你可以嘗試把它放在你的文件系統中。編寫一個代碼,將startdate寫入文件,並在需要時從該文件中獲取它。 ? – Shoogle

回答

1

PHP沒有站點範圍的變量。您可以做的最好的事情是將作業放在腳本中,例如site.php,並讓所有頁面以require 'site.php';開頭來初始化這些變量。