2015-02-01 2 views
1

Попытка создать тему ребенка из Wordpress двадцать четыре темы. Wordpress Codex говоритПутаница создания детской темы правильно в wordpress

Обратите внимание, что предыдущий метод был импортировать родительский THEME таблицы стилей с помощью @import: это уже не лучшая практика. Правильный метод , связанный с созданием таблицы стилей родительской темы, заключается в использовании функции wp_enqueue_script() в функции child.php вашей дочерней темы.

Функция, которая отвечает стилей загрузки и файлов JavaScript в twentyfifteen является

function twentyfifteen_scripts() { 
    // Add custom fonts, used in the main stylesheet. 
    wp_enqueue_style('twentyfifteen-fonts', twentyfifteen_fonts_url(), array(), null); 

    // Add Genericons, used in the main stylesheet. 
    wp_enqueue_style('genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.2'); 

    // Load our main stylesheet. 
    wp_enqueue_style('twentyfifteen-style', get_stylesheet_uri()); 

    // Load the Internet Explorer specific stylesheet. 
    wp_enqueue_style('twentyfifteen-ie', get_template_directory_uri() . '/css/ie.css', array('twentyfifteen-style'), '20141010'); 
    wp_style_add_data('twentyfifteen-ie', 'conditional', 'lt IE 9'); 

    // Load the Internet Explorer 7 specific stylesheet. 
    wp_enqueue_style('twentyfifteen-ie7', get_template_directory_uri() . '/css/ie7.css', array('twentyfifteen-style'), '20141010'); 
    wp_style_add_data('twentyfifteen-ie7', 'conditional', 'lt IE 8'); 

    wp_enqueue_script('twentyfifteen-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20141010', true); 

    if (is_singular() && comments_open() && get_option('thread_comments')) { 
     wp_enqueue_script('comment-reply'); 
    } 

    if (is_singular() && wp_attachment_is_image()) { 
     wp_enqueue_script('twentyfifteen-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array('jquery'), '20141010'); 
    } 

    wp_enqueue_script('twentyfifteen-script', get_template_directory_uri() . '/js/functions.js', array('jquery'), '20141212', true); 
    wp_localize_script('twentyfifteen-script', 'screenReaderText', array(
     'expand' => '<span class="screen-reader-text">' . __('expand child menu', 'twentyfifteen') . '</span>', 
     'collapse' => '<span class="screen-reader-text">' . __('collapse child menu', 'twentyfifteen') . '</span>', 
    )); 
} 
add_action('wp_enqueue_scripts', 'twentyfifteen_scripts'); 

Таким образом, после копирования его из родителя functions.php и вставить его в functions.php то, что я сделал ребенка: 1.Changed функции имя. 2.Replaced линия

wp_enqueue_style('twentyfifteen-style', get_stylesheet_uri()); 

с

wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css'); 

3.Removed код для файлов JavaScript.

Я также удаляю другие таблицы стилей, которые не являются основной таблицей стилей родительской темы? Как правильно включить другую таблицу стилей в тему ребенка? (? Я могу просто использовать wp_enqueue_style('child-style', get_stylesheet_directory_uri() . '/style.css');)

ответ

4

Вам не нужно много, чтобы сделать детскую тему, большая часть кода в вашем вопросе не требуется:

  1. создать папку в «темах» каталог и назовите его, что бы вы ни хотели. twentyfifteenchild прояснит
  2. создать файл под названием style.css и поместить следующее в верхней:

    /* 
    Theme Name: Twenty Fifteen Child 
    Theme URI: http://example.com/twenty-fifteen-child/ 
    Description: Twenty Fifteen Child Theme 
    Author:  John Doe 
    Author URI: http://example.com 
    Template:  twentyfifteen 
    Version:  1.0.0 
    License:  GNU General Public License v2 or later 
    License URI: http://www.gnu.org/licenses/gpl-2.0.html 
    Tags:   light, dark, two-columns, right-sidebar, responsive-layout,    accessibility-ready 
    Text Domain: twenty-fifteen-child 
    */ 
    
  3. Создать файл functions.php и вставьте в него следующее:

    <?php 
    add_action('wp_enqueue_scripts', 'theme_enqueue_styles'); 
    function theme_enqueue_styles() { 
        wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css'); 
    
    } 
    
+0

Да, мне просто интересно, что этого будет достаточно или нет. Спасибо за уточнение. – jennifer

+0

Ссылка на родительскую тему будет выполнена с помощью шаблона: xxx xxx должно быть точным именем case-sensitiv, таким как имя папки родительских тем – MarkusEgle

0

Странно, я могу ответить, но не комментировать ... Я также хочу знать, почему люди используют @import в CSS, когда WordPress конкретно говорит, что это так:

Следующая примерная функция будет работать, только если ваша родительская тема использует только один основной стиль style.css для хранения всех css. Если ваша тема имеет более одного .css-файла (например, ie.css, style.css, main.css), вам необходимо будет поддерживать все зависимые от родительской темы.

add_action('wp_enqueue_scripts', 'theme_enqueue_styles'); 
function theme_enqueue_styles() { 
    wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css'); 

} 

Установка «родительский стиль» в качестве зависимости гарантирует, что после нее будет загружена таблица стилей дочерних тегов. Смотрите здесь более подробное обсуждение:

add_action('wp_enqueue_scripts', 'theme_enqueue_styles'); 
function theme_enqueue_styles() { 
    wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css'); 
    wp_enqueue_style('child-style', 
     get_stylesheet_directory_uri() . '/style.css', 
     array('parent-style') 
    ); 
} 

самом деле я узнал теперь, что я не всегда делаю зависимости штуковина ... нуб/дизайнер из строя или плохая документация не в состоянии ...?!?

Смежные вопросы