13. Поля даты, времени и цвета | Field Forge - Произвольные поля, созданные для скорости
Скачать Войти

13. Поля даты, времени и цвета

Поля для временных данных и значений визуального оформления.

Выбор даты

Возвращает строку даты, отформатированную в соответствии с настройкой return_format.

php
$date = get_field( 'event_date' );
// Stored internally as 'Y-m-d' (e.g., '2024-12-25').
// `return_format` controls what get_field() returns: when unset, you get the
// raw stored value (`Y-m-d`); when set to a PHP date format like `F j, Y`,
// the field re-formats automatically.

echo '<time datetime="' . esc_attr( $date ) . '">' . esc_html( $date ) . '</time>';

// Parse and reformat ad hoc
$raw = get_field( 'event_date' );
$timestamp = strtotime( $raw );
echo '<p>Event: ' . date_i18n( 'l, F j, Y', $timestamp ) . '</p>';

// Compare dates
$event_date = get_field( 'event_date' );
$now = current_time( 'Y-m-d' );
if ( $event_date && strtotime( $event_date ) >= strtotime( $now ) ) {
    echo '<span class="upcoming">Upcoming</span>';
} else {
    echo '<span class="past">Past Event</span>';
}

Выбор времени (PRO)

Возвращает строку времени.

php
$time = get_field( 'opening_time' );
// Returns: formatted string per return_format, e.g., '09:00:00' or '9:00 AM'

echo '<span class="time">' . esc_html( $time ) . '</span>';

// Combine date and time
$date = get_field( 'event_date' );
$time = get_field( 'event_time' );
echo '<p>Event: ' . esc_html( $date ) . ' at ' . esc_html( $time ) . '</p>';

Выбор цвета

Возвращает строку цвета в шестнадцатеричном формате (или rgba, если включена непрозрачность).

php
$color = get_field( 'brand_color' );
// Returns: '#FF5733' or 'rgba(255,87,51,0.8)' if opacity enabled

echo '<div style="background-color: ' . esc_attr( $color ) . ';">Colored block</div>';

// Use as CSS custom property
$primary = get_field( 'primary_color', 'options' );
$secondary = get_field( 'secondary_color', 'options' );
echo '<style>:root { --color-primary: ' . esc_attr( $primary ) . '; --color-secondary: ' . esc_attr( $secondary ) . '; }</style>';

ИИ-ассистент Forge Онлайн

Привет! Я ИИ-ассистент Field Forge. Спрашивайте меня о чём угодно по плагину — настройка, возможности, устранение неполадок или разработка.

Только что
На базе Forge AI · Просмотр документации