1. Початок роботи | Field Forge - Кастомні поля, створені для швидкості
Завантажити Увійти

1. Початок роботи

Спільна діагностика Forge Suite

Коли Field Forge активний, спільна панель Forge Suite > Налаштування та здоров’я доступна в адмінці WordPress. Його дія AJAX тільки для читання — forge_suite_health_check; вона вимагає manage_options та локалізований forge_suite_health_check nonce. Відповідь повертає діагностику для активних плагінів Forge, локальні записи ліцензій, готовність віджета кредитів, Avakode API /health, постійні посилання та плагіни джерел міграції/інтеграції, такі як ACF та ACF Pro. Він не імпортує дані ACF, не створює групи полів, не записує значення полів, не викликає кінцеві точки AI, не витрачає кредити та не змінює стан ліцензії/Freemius.

Як налаштувати вашу тему для роботи з Field Forge

Field Forge зберігає значення в кастомних таблицях бази даних (wp_fieldforge_values), а не в wp_postmeta. Він надає сумісний з ACF шар функцій, тому існуючий код теми працює без модифікацій. Це означає, що ви можете використовувати get_field(), the_field(), have_rows() та всі інші знайомі функції — Field Forge реєструє їх автоматично, коли ACF не активний. Під час запитів активації ACF Field Forge віддає перевагу ACF, щоб ACF Pro можна було активувати для міграції без фатальної помилки повторного оголошення PHP.

Перевірка, чи активний Field Forge:
php
// functions.php -- ensure field functions are always available
if ( ! function_exists( 'get_field' ) ) {
    // Field Forge (or ACF) is not active -- provide fallbacks
    function get_field( $selector, $post_id = false ) {
        return get_post_meta( $post_id ?: get_the_ID(), $selector, true );
    }
}

Цей шаблон забезпечує, що ваша тема ніколи не зламається, навіть якщо Field Forge деактивовано. Резервне читання з wp_postmeta, де стандартний WordPress зберігає кастомні поля.

Перевірка наявності Field Forge конкретно:
php
// Check for Field Forge (not ACF)
if ( defined( 'FIELDFORGE_VERSION' ) ) {
    // Field Forge-specific code here
    $version = FIELDFORGE_VERSION; // e.g., '1.2.0'
}

// Check for Field Forge PRO features
if ( defined( 'FIELDFORGE_PRO' ) && FIELDFORGE_PRO ) {
    // PRO-only code: repeaters, flexible content, options pages, etc.
}
Основний доступ до полів у шаблоні:
php
<?php
// single.php -- display custom fields on a post
$subtitle = get_field( 'subtitle' );
$hero_image = get_field( 'hero_image' ); // Returns array when return_format = 'array'

if ( $subtitle ) : ?>
    <h2 class="entry-subtitle"><?php echo esc_html( $subtitle ); ?></h2>
<?php endif; ?>

<?php if ( $hero_image ) : ?>
    <img src="<?php echo esc_url( $hero_image['url'] ); ?>"
         alt="<?php echo esc_attr( $hero_image['alt'] ); ?>"
         width="<?php echo esc_attr( $hero_image['width'] ); ?>"
         height="<?php echo esc_attr( $hero_image['height'] ); ?>">
<?php endif; ?>
Виведення поля безпосередньо:
php
<p class="lead"><?php the_field( 'lead_text' ); ?></p>
Використання полів у архівних шаблонах:
php
<?php // archive.php or index.php
if ( have_posts() ) :
    while ( have_posts() ) : the_post(); ?>
        <article class="post-card">
            <?php $thumb = get_field( 'card_thumbnail' ); ?>
            <?php if ( $thumb ) : ?>
                <img src="<?php echo esc_url( $thumb['url'] ); ?>"
                     alt="<?php echo esc_attr( $thumb['alt'] ); ?>"
                     class="post-card__image">
            <?php endif; ?>
            <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
            <p><?php the_field( 'excerpt_text' ); ?></p>
        </article>
    <?php endwhile;
endif; ?>
Використання полів у шаблоні сторінки:
php
<?php
/**
 * Template Name: About Us
 */
get_header();

$team_photo   = get_field( 'team_photo' );
$mission      = get_field( 'mission_statement' );
$founded_year = get_field( 'founded_year' );
?>

<main class="about-page">
    <section class="about-hero">
        <?php if ( $team_photo ) : ?>
            <img src="<?php echo esc_url( $team_photo['url'] ); ?>"
                 alt="<?php echo esc_attr( $team_photo['alt'] ); ?>">
        <?php endif; ?>
        <div class="about-hero__content">
            <h1><?php the_title(); ?></h1>
            <?php if ( $mission ) : ?>
                <blockquote><?php echo esc_html( $mission ); ?></blockquote>
            <?php endif; ?>
            <?php if ( $founded_year ) : ?>
                <p class="founded">Established <?php echo esc_html( $founded_year ); ?></p>
            <?php endif; ?>
        </div>
    </section>
</main>

<?php get_footer(); ?>

Декларація підтримки теми

Не потрібно спеціального виклику add_theme_support(). Field Forge автоматично активує свій шар сумісності, коли ACF не активний. Якщо ACF активний разом з Field Forge, функції ACF мають пріоритет, а Field Forge діє лише як бекенд для зберігання. Така ж охорона застосовується під час активації wp-admin та API плагінів WordPress, тому активація ACF Pro після того, як Field Forge вже активний, не повторно оголошує get_field().

Рекомендована структура теми

Організуйте файли вашої теми для чистої інтеграції Field Forge:

text
my-theme/
  functions.php             # Load field setup, register blocks
  inc/
    fieldforge-setup.php    # Options pages, programmatic field groups
    template-functions.php  # Helper functions wrapping get_field()
  template-parts/
    content-*.php           # Partial templates using fields
    builder/                # Flexible content section templates
  blocks/                   # PHP block templates
  fieldforge-json/          # Local JSON sync directory (PRO)
Створення допоміжних функцій для повторюваних шаблонів полів:
php
<?php
// inc/template-functions.php

/**
 * Get the hero image URL with a fallback.
 *
 * @param int|false $post_id Post ID or false for current post.
 * @return string Image URL.
 */
function theme_get_hero_image( $post_id = false ) {
    $image = get_field( 'hero_image', $post_id );
    if ( $image && isset( $image['url'] ) ) {
        return $image['url'];
    }
    return get_template_directory_uri() . '/assets/img/default-hero.jpg';
}

/**
 * Render social links from options page.
 */
function theme_render_social_links() {
    $platforms = [ 'facebook', 'twitter', 'instagram', 'linkedin', 'youtube' ];
    echo '<div class="social-links">';
    foreach ( $platforms as $platform ) {
        $url = get_field( 'social_' . $platform, 'options' );
        if ( $url ) {
            printf(
                '<a href="%s" class="social-link social-link--%s" target="_blank" rel="noopener">%s</a>',
                esc_url( $url ),
                esc_attr( $platform ),
                esc_html( ucfirst( $platform ) )
            );
        }
    }
    echo '</div>';
}

Асистент ШІ Forge Онлайн

Привіт! Я асистент ШІ Field Forge. Запитайте мене про будь-що щодо плагіна — налаштування, можливості, усунення несправностей чи розробку.

Щойно
Працює на Forge AI · Переглянути документацію