문제

I'm using Kirby CMS and creating a little snippet which limits by posts by what number they are, and what date they are. A way to create a 'autopost' system basically.

$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

So I have that little bit which creates my $latest variable which I can then use to control the posts that are displayed.

My problem is, I don't want to have to change my $startdate on every different kind of page template I have, so I want to make it site-wide somehow.

I tried putting it as a snippet with Kirby's snippet() function but that doesn't work. The snippets must be being brought into the page after the snippet has already been run I guess.

How can I make my snippet apply to my whole site?

도움이 되었습니까?

해결책

PHP doesn't have site-wide variables. The best you can do is put the assignments in a script, e.g. site.php, and have all your pages begin with require 'site.php'; to initialize these variables.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top