I have a news section on our website and I want to only show the current years articles unless it is January, February or March. Since those months are at the beginning of the year, I don't want the page to not have any content.
I have been able to figure out the PHP to get the current date and subtract 2 years (so I can show last year's posts).
<?$date = strtotime('{current_time format="%Y"} -2 year');?>
I also figured out how to do the {if/if:elseif} statements to check which month we are currently in and if it is January do this. February do this. March do this. All the other months do that.
{if {current_time format="%m"} == "01"}
<p>This is January</p>
{if:elseif {current_time format="%m"} == "02"}
<p>This is February</p>
{if:elseif {current_time format="%m"} == "03"}
<p>This is March</p>
{if:else}
<p>This is all the other months</p>
{/if}
Both of the codes above work well independently of each other, but when I put them together the {if:elseif} quits working and it defaults to the last {if:else} content.
Anyone know why? Here is the final code I tried:
{if {current_time format="%m"} == "01"}
<?$date = strtotime('{current_time format="%Y"} -2 year');?>
{if:elseif {current_time format="%m"} == "02"}
<?$date = strtotime('{current_time format="%Y"} -2 year');?>
{if:elseif {current_time format="%m"} == "03"}
<?$date = strtotime('{current_time format="%Y"} -2 year');?>
{if:else}
<?$date = strtotime('{current_time format="%Y"} -1 year');?>
{/if}