我最後創建了一個template-name-child
文件夾。
放置有下列文件:
- 的style.css
- screenshot.jpg
- 的functions.php
- 的script.js
- 的readme.txt
的最重要的部分是functions.php:
<?php
// template
//add_action('wp_enqueue_scripts', 'theme_enqueue_styles');
wp_enqueue_scripts('wp_enqueue_scripts', 'theme_enqueue_styles');
function theme_enqueue_styles()
{
// template-name == parent-template-name
wp_enqueue_style('template-name', get_template_directory_uri() . '/style.css', array('bootstrap', 'jquery', 'font-awesome'));
}
// custom scripts
function theme_enqueue_scripts()
{
wp_enqueue_script('frontend-ajax', get_stylesheet_directory_uri() . '/js/script.js', array('jquery'), null, true);
wp_localize_script('frontend-ajax', 'custom_vars',
array(
'bandname' => get_metadata("user", get_current_user_id(), "band_name", true),
)
);
}
add_action('wp_enqueue_scripts', 'theme_enqueue_scripts');
?>
現在我能夠通過
console.log(my_vars.bandname);
從我script.js
變量調用該readme.txt包含
=== Template Name Child ===
Author: Your Name
Tags: black, blue, white, light, dark, two-columns, right-sidebar, fixed-layout, responsive-layout, custom-background, custom-header, custom-menu, editor-style, featured-images, microformats, post-formats, rtl-language-support, sticky-post, theme-options, threaded-comments, translation-ready
Requires at least: 4.0
Tested up to: 4.4.1
Stable tag: 1.0
License: GNU General Public License v3 or later
License URI: http://www.gnu.org/licenses/gpl.html
== Description ==
Modern & beautiful responsive theme.
的風格。css包含:
/*
Theme Name: Template Name Child
Theme URI: http://example.com/twenty-fifteen-child/
Description: Template Name Child Theme
Author: Your Name
Author URI: https://www.yourUrl.com
Template: template-name
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: dark
Text Domain: template-name-child
*/