如果current_time,则执行此操作,否则请执行此操作


If current_time then do this else do this

我有一个表达式引擎网站,我想创建一个只填充一年故事的新闻模板。以下代码确实有效,并使用正确的故事年份填充页面。

<?$date = strtotime('{current_time format="%Y"} -1 year');?>
    {exp:channel:entries channel="news" start_on="<?echo date('Y', $date);?>-12-31 20:00" dynamic="no"}

但是在一月和二月,我的页面上不会有很多帖子,所以我想像这样:

{if '{current_time format="%M"} = "Jan"'}
<?$date = strtotime('{current_time format="%Y"} -2 year');?>
{exp:channel:entries channel="news" start_on="<?echo date('Y', $date);?>-12-31 20:00" dynamic="no"}
{if:else}
<?$date = strtotime('{current_time format="%Y"} -1 year');?>
    {exp:channel:entries channel="news" start_on="<?echo date('Y', $date);?>-12-31 20:00" dynamic="no"}
{/if}

我似乎无法弄清楚 IF 当前时间 = 1 月的 PHP

根据此处找到的文档 https://ellislab.com/expressionengine/user-guide/templates/date_variable_formatting.html

你应该使用

{if {current_time format="%M"} == "Jan"}