【发布时间】:2020-05-10 00:26:30
【问题描述】:
我是 Twig 的新手,在以 AP 格式显示日期时遇到问题。我正在为日期月份设置一个变量,并且我有一个 if 语句将月份编号设置为该月份的月份名称缩写。但是,它不起作用。我相信我的语法是错误的,因为这是一个很长的条件。任何帮助将不胜感激!
{% set show_month = show.get_field('start_date') | date('n') - 1 %}
{% set show_month_numerical = show.get_field('start_date') | date('m') %}
{% if show_month_numerical == '01' %}
{% set show_month_apstyle = 'Jan.' %}
{% elseif show_month_numerical == '02' %}
{% set show_month_apstyle = 'Feb.'%}
{% elseif show_month_numerical == '08' %}
{% set show_month_apstyle = 'Aug.'%}
{% elseif show_month_numerical == '09' %}
{%s set how_month_apstyle = 'Sept.'%}
{% elseif show_month_numerical == '10' %}
{% set show_month_apstyle = 'Oct.'%}
{% elseif show_month_numerical == '11' %}
{% set show_month_apstyle = 'Nov.'%}
{% elseif show_month_numerical == '12' %}
{% set show_month_apstyle = 'Dec.'%}
{% endif %}
<h2 class="beta">
<span class="start-date-mdy">{{ show.get_field('start_date')|date('m j, Y') }}</span>
</h2>
【问题讨论】:
标签: wordpress if-statement twig conditional-statements