tananin
2/21/2019 - 2:49 PM

Unyson

Создаём опции для темы с Unyson

  • Создадим структуру директорий в нашей теме: {theme}/framework-customizations/theme/options/settings.php
  • Создадим файл settings.php
  • Пример конфигурации
<?php if ( ! defined( 'FW' ) ) {
    die( 'Forbidden' );
}

$options = array(
    'general' => array(
        'type' => 'tab',
        'title' => 'Основные',
        'options' => array(
            'logo'  => array( 'type' => 'upload', 'label' => 'Логотип' ),
            'favicon'  => array( 'type' => 'upload', 'label' => 'Иконка сайта' ),
            'phone'  => array( 'type' => 'text', 'label' => 'Телефон на сайте' ),
        ),
    ),
    'header' => array(
        'type' => 'tab',
        'title' => 'Шапка сайта',
        'options' => array(
            'icon1' => array(
                'type' => 'box',
                'title' => 'Иконка 1',
                'options' => array(
                    'icon'  => array( 'type' => 'text', 'label' => 'Иконка'),
                    'link'  => array( 'type' => 'text', 'label' => 'Ссылка'),
                    'text'  => array( 'type' => 'text', 'label' => 'Подпись' ),
                ),
            ),
            'icon2' => array(
                'type' => 'box',
                'title' => 'Иконка 2',
                'options' => array(
                    'icon'  => array( 'type' => 'text', 'label' => 'Иконка'),
                    'link'  => array( 'type' => 'text', 'label' => 'Ссылка'),
                    'text'  => array( 'type' => 'text', 'label' => 'Подпись' ),
                ),
            ),
        ),
    ),
    'footer' => array(
        'type' => 'tab',
        'title' => 'Подвал сайта',
        'options' => array(
            'logo-footer'  => array( 'type' => 'upload', 'label' => 'Логотип для подвала'),
            'uslugi'  => array( 'type' => 'text', 'label' => 'Наши услуги'),
            'icon'  => array( 'type' => 'text', 'label' => 'Иконка'),
            'text'  => array( 'type' => 'text', 'label' => 'Город'),
            'desc'  => array( 'type' => 'text', 'label' => 'Адрес'),
            'copy'  => array( 'type' => 'text', 'label' => 'Копирайт')
        ),
    ),
    'metric' => array(
        'type' => 'tab',
        'title' => 'Счётчики',
        'options' => array(
            'yandex'  => array( 'type' => 'textarea', 'label' => 'Яндекс метрика', 'desc' => 'Код счётчика' ),
            'google'  => array( 'type' => 'textarea', 'label' => 'Google аналитика', 'desc' => 'Код счётчика' ),
            'open'  => array( 'type' => 'textarea', 'label' => 'OpenStats аналитика', 'desc' => 'Код счётчика' ),
        ),
    ),
    'plagin' => array(
        'type' => 'tab',
        'title' => 'Плагины JS',
        'options' => array(
            'plagin1'  => array( 'type' => 'textarea', 'label' => 'Плагин 1', 'desc' => 'Код плагина' ),
            'plagin2'  => array( 'type' => 'textarea', 'label' => 'Плагин 2', 'desc' => 'Код плагина' ),
            'plagin3'  => array( 'type' => 'textarea', 'label' => 'Плагин 3', 'desc' => 'Код плагина' ),
        ),
    ),
);
  • Выводим текстовую переменную конфигурации в шаблоне
<?php echo fw_get_db_settings_option('phone') ?>
  • Вывод ссылки на изображение
<?php echo fw_get_db_settings_option('footer-logo')['url']; ?>

Кастомизация готовых расширений

  1. Создаём директории /framework-customizations/extensions/shortcodes/shortcodes
  2. Копируем нужное нам расширение, к примеру section
  3. Добавляем или меняем опции в файле: options.php

Создания расширения

Документация http://manual.unyson.io/en/latest/extension/shortcodes/index.html#content

  • Создайте новую директорию в /framework-customizations/extensions/shortcodes/shortcodes

  • Создайте файл config.php

    <?php if (!defined('FW')) die('Forbidden');
      $cfg = array(
      'page_builder' => array(
      'title'         => 'Название шорткода',
      'description'   => 'Описание',
      'tab'           => 'Новая вкладка',
      'popup_size'    => 'small', // can be large, medium or small
      )
    

    );

  • Задаём иконку шорткода. Файл page_builder.png в директории your-shortcode}/static/img/

  • Опции шорткода. Создадим файл options.php

<?php if (!defined('FW')) die('Forbidden');
$options = array(
    'demo_text'   => array(
        'label'   => __('Demo text label', '{domain}'),
        'desc'    => __('Demo text description', '{domain}'),
        'help'    => __('Demo text help', '{domain}'),
        'type'    => 'text'
    ),
    'demo_select' => array(
        'label'   => __('Demo select label', '{domain}'),
        'desc'    => __('Demo select description', '{domain}'),
        'type'    => 'select',
        'choices' => array(
            'c1'  => __('Choice 1', '{domain}'),
            'c2'  => __('Choice 2', '{domain}'),
            'c3'  => __('Choice 3', '{domain}')
        ),
        'value'   => 'c2'
    )
);
  • Вывод данных из шорткода. Создадим файл {your-shortcode}/views/view.php