Changing my navigation based on date

2019-07-23 07:02发布

I would like my site to display different seasonal projects based on the date. Currently, I call the 'Top Winter Projects' section of my right navigation with the following code:

<?php include (TEMPLATEPATH . '/stub_favorites.php'); ?>

Is there a way that I could use a php include based on date? So if its January 14, call /stub_favorites.php, but if its March 10, call stub_favorites1.php? I'm new to php so bear with me.

My website is as followed: http://www.merrimentdesign.com

标签: php wordpress
2条回答
够拽才男人
2楼-- · 2019-07-23 07:19

The most dead easy way to display one include per month:

<?php
   $filename = "month".date("n").".php";
   if (file_exists($filename)) include($filename);

then add files:

month1.php
month2.php
month3.php

the right file will be included for each month. The script will fail silently if a month does not exist. To make this work for calendar weeks instead, use date("W");. A full reference of date parameters can be found in the manual.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-07-23 07:23

Take a look at PHPs Date/Time Functions: http://php.net/manual/en/ref.datetime.php

You can do something like:

if (date('m/d/Y') < date('m/d/Y', strtotime("12/1/2011"))) {
    //Display something
}
else {
    //Display something different
}
查看更多
登录 后发表回答