我试图在Divi主题下创建一个非常基本的WordPress子主题。我只是做了简单的步骤,以确保基本结构是正确的,但我没有看到任何样式。
我在名为divi-child的主题下创建了一个新目录 并在其中放入三个文件:category.php,style.css和functions.php。
对于category.php,我所做的是制作了index.php的副本,并将其命名为category.php。我在顶部做了一些小改动,只是为了测试而放入一个h1标签。这是category.php的摘录:
<?php get_header(); ?>
<h1 id="styletest">Marker Text Test</h1>
<div id="main-content">
.... rest of original index.php
这是style.css:
/*
Theme Name: divi-child
Theme URI: http://www.elegantthemes.com/gallery/divi/
Description: Child theme for the Divi theme
Author: Elegant Themes
Author URI: http://www.elegantthemes.com
Template: Divi
Version: 1.0.1
*/
#styletest {
background: green;
}
这里是functions.php:
<?php
function my_theme_enqueue_styles() {
$parent_style = 'divi-style'; // This is 'divi-style' for the Divi theme.
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'divi-child-style',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style ),
wp_get_theme()->get('Version')
);
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
?>
我可以在我的类别页面上看到测试h1文本,但它没有绿色背景样式,所以我的孩子样式文件没有被阅读。我确实激活了新的儿童主题。请指教。您可以自己查看的URL是gloudle.com(只需转到帖子并在侧栏中选择一个类别)。谢谢!
答案 0 :(得分:0)
只要您对此没有麻烦,就可以使用Divi Child theme builder,我自己在很多场合都使用过。希望对您有帮助
因此,根据评论说我没有足够回答这个问题,我将详细说明答案。
a)style.css,其中包含以下代码
/*---------------------------------------------------------------------------------
主题名称:Divi Child Theme
主题URI:
说明:
作者:
作者URI:
范本:Divi
版本:1.0.0
许可证:GNU通用公共许可证v2或更高版本
许可证URI:http://www.gnu.org/licenses/gpl-2.0.html
--------------------------------这里有其他CSS -------------- ---------------- * / b)login-editor.php ,通常在主题中不需要,但是当您要编辑登录屏幕时,这对于divi很有用。您在此文件中需要的代码是
<?php
如果(!defined('ABSPATH'))die();
//登录编辑器
函数ds_register_login_editor($ wp_customize){
// New Login Editor Panel
$wp_customize->add_panel( 'ds_login_editor_panel', array(
'priority' => 30,
'capability' => 'edit_theme_options',
'title' => __('Login Editor', login_editor_title),
'description' => __('Customize the login of your website.', login_editor_title),
));
// New Sections
$wp_customize->add_section('ds_login_logo_section', array(
'priority' => 5,
'title' => __('Logo', login_editor_title),
'panel' => 'ds_login_editor_panel',
));
$wp_customize->add_section('ds_login_text_section', array(
'priority' => 10,
'title' => __('Text Options', login_editor_title),
'panel' => 'ds_login_editor_panel',
));
$wp_customize->add_section('ds_login_background_section', array(
'priority' => 15,
'title' => __('Background', login_editor_title),
'panel' => 'ds_login_editor_panel',
));
$wp_customize->add_section('ds_login_form_bg_section', array(
'priority' => 20,
'title' => __('Form Background', login_editor_title),
'panel' => 'ds_login_editor_panel',
));
$wp_customize->add_section('ds_login_form_section', array(
'priority' => 25,
'title' => __('Form Style', login_editor_title),
'panel' => 'ds_login_editor_panel',
));
$wp_customize->add_section('ds_login_field_section', array(
'priority' => 30,
'title' => __('Fields Style', login_editor_title),
'panel' => 'ds_login_editor_panel',
));
$wp_customize->add_section('ds_login_button_section', array(
'priority' => 35,
'title' => __('Edit Button', login_editor_title),
'panel' => 'ds_login_editor_panel',
));
$wp_customize->add_section('ds_login_advanced_section', array(
'priority' => 40,
'title' => __('Custom CSS', login_editor_title),
'panel' => 'ds_login_editor_panel',
));
// LOGO OPTIONS
$wp_customize->add_setting('ds_login_logo', array(
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'ds_login_logo', array(
'label' => __('Login Logo', login_editor_title),
'section' => 'ds_login_logo_section',
'priority' => 5,
'settings' => 'ds_login_logo'
)));
$wp_customize->add_setting('ds_login_logo_width', array(
'default' => '84px',
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control('ds_login_logo_width', array(
'label' => __('Logo Width', login_editor_title),
'section' => 'ds_login_logo_section',
'priority' => 10,
'settings' => 'ds_login_logo_width'
));
$wp_customize->add_setting('ds_login_logo_height', array(
'default' => '84px',
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control('ds_login_logo_height', array(
'label' => __('Logo Height', login_editor_title),
'section' => 'ds_login_logo_section',
'priority' => 15,
'settings' => 'ds_login_logo_height'
));
$wp_customize->add_setting('ds_login_logo_padding', array(
'default' => '5px',
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control('ds_login_logo_padding', array(
'label' => __('Padding Bottom', login_editor_title),
'section' => 'ds_login_logo_section',
'priority' => 20,
'settings' => 'ds_login_logo_padding'
));
$wp_customize->add_setting('ds_login_bg_image', array(
'type' => 'option',
'capability' => 'edit_theme_options',
));
// BACKGROUND IMAGE EDITS
$wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'ds_login_bg_image', array(
'label' => __('Background Image', login_editor_title),
'section' => 'ds_login_background_section',
'priority' => 5,
'settings' => 'ds_login_bg_image'
)));
$wp_customize->add_setting('ds_login_bg_color', array(
'default' => '#F1F1F1',
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'ds_login_bg_color', array(
'label' => __('Background Color', login_editor_title),
'section' => 'ds_login_background_section',
'priority' => 10,
'settings' => 'ds_login_bg_color'
)));
$wp_customize->add_setting('ds_login_bg_size', array(
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control('ds_login_bg_size', array(
'label' => __('Background Size', login_editor_title),
'section' => 'ds_login_background_section',
'priority' => 15,
'settings' => 'ds_login_bg_size'
));
// FORM BACKGROUND EDITS
$wp_customize->add_setting('ds_login_form_bg_image', array(
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'ds_login_form_bg_image', array(
'label' => __('Background Image', login_editor_title),
'section' => 'ds_login_form_bg_section',
'priority' => 5,
'settings' => 'ds_login_form_bg_image'
)));
$wp_customize->add_setting('ds_login_form_bg_color', array(
'default' => '#FFF',
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'ds_login_form_bg_color', array(
'label' => __('Background Color', login_editor_title),
'section' => 'ds_login_form_bg_section',
'priority' => 10,
'settings' => 'ds_login_form_bg_color'
)));
$wp_customize->add_setting('ds_login_form_width', array(
'default' => '320px',
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control('ds_login_form_width', array(
'label' => __('Width', login_editor_title),
'section' => 'ds_login_form_section',
'priority' => 15,
'settings' => 'ds_login_form_width'
));
$wp_customize->add_setting('ds_login_form_height', array(
'default' => '194px',
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control('ds_login_form_height', array(
'label' => __('Height', login_editor_title),
'section' => 'ds_login_form_section',
'priority' => 20,
'settings' => 'ds_login_form_height'
));
$wp_customize->add_setting('ds_login_form_padding', array(
'default' => '26px 24px 46px',
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control('ds_login_form_padding', array(
'label' => __('Padding', login_editor_title),
'section' => 'ds_login_form_section',
'priority' => 25,
'settings' => 'ds_login_form_padding'
));
// FORM FIELDS
$wp_customize->add_setting('ds_login_field_width', array(
'default' => '100%',
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control('ds_login_field_width', array(
'label' => __('Input Field Width', login_editor_title),
'section' => 'ds_login_field_section',
'priority' => 5,
'settings' => 'ds_login_field_width'
));
$wp_customize->add_setting('ds_login_field_margin', array(
'default' => '2px 6px 16px 0px',
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control('ds_login_field_margin', array(
'label' => __('Input Field Margin', login_editor_title),
'section' => 'ds_login_field_section',
'priority' => 10,
'settings' => 'ds_login_field_margin'
));
$wp_customize->add_setting('ds_login_field_bg', array(
'default' => '#FFF',
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'ds_login_field_bg', array(
'label' => __('Input Field Background', login_editor_title),
'section' => 'ds_login_field_section',
'priority' => 15,
'settings' => 'ds_login_field_bg'
)));
$wp_customize->add_setting('ds_login_field_color', array(
'default' => '#333',
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'ds_login_field_color', array(
'label' => __('Input Field Color', login_editor_title),
'section' => 'ds_login_field_section',
'priority' => 20,
'settings' => 'ds_login_field_color'
)));
$wp_customize->add_setting('ds_login_field_label', array(
'default' => '#777',
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'ds_login_field_label', array(
'label' => __('Label Color', login_editor_title),
'section' => 'ds_login_field_section',
'priority' => 25,
'settings' => 'ds_login_field_label'
)));
// BUTTON STYLES
$wp_customize->add_setting('ds_login_button_bg', array(
'default' => '#2EA2CC',
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'ds_login_button_bg', array(
'label' => __('Button Background', login_editor_title),
'section' => 'ds_login_button_section',
'priority' => 5,
'settings' => 'ds_login_button_bg'
)));
$wp_customize->add_setting('ds_login_button_border', array(
'default' => '#0074A2',
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'ds_login_button_border', array(
'label' => __('Button Border', login_editor_title),
'section' => 'ds_login_button_section',
'priority' => 10,
'settings' => 'ds_login_button_border'
)));
$wp_customize->add_setting('ds_login_button_hover_bg', array(
'default' => '#1E8CBE',
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'ds_login_button_hover_bg', array(
'label' => __('Button Background (Hover)', login_editor_title),
'section' => 'ds_login_button_section',
'priority' => 15,
'settings' => 'ds_login_button_hover_bg'
)));
$wp_customize->add_setting('ds_login_button_hover_border', array(
'default' => '#0074A2',
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'ds_login_button_hover_border', array(
'label' => __('Button Border (Hover)', login_editor_title),
'section' => 'ds_login_button_section',
'priority' => 20,
'settings' => 'ds_login_button_hover_border'
)));
$wp_customize->add_setting('ds_login_button_shadow', array(
'default' => '#78C8E6',
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'ds_login_button_shadow', array(
'label' => __('Button Box Shadow', login_editor_title),
'section' => 'ds_login_button_section',
'priority' => 25,
'settings' => 'ds_login_button_shadow'
)));
$wp_customize->add_setting('ds_login_button_color', array(
'default' => '#FFF',
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'ds_login_button_color', array(
'label' => __('Button Color', login_editor_title),
'section' => 'ds_login_button_section',
'priority' => 30,
'settings' => 'ds_login_button_color'
)));
// CUSTOM CSS
$wp_customize->add_setting('ds_login_custom_css', array(
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control('ds_login_custom_css', array(
'label' => __('Not found the option you wanted? Add your own CSS here...', login_editor_title),
'type' => 'textarea',
'section' => 'ds_login_advanced_section',
'priority' => 5,
'settings' => 'ds_login_custom_css'
));
$wp_customize->add_setting('ds_login_text_color', array(
'default' => '#999',
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'ds_login_text_color', array(
'label' => __('Text Color', login_editor_title),
'section' => 'ds_login_text_section',
'priority' => 5,
'settings' => 'ds_login_text_color'
)));
$wp_customize->add_setting('ds_login_text_color_hover', array(
'default' => '#2EA2CC',
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'ds_login_text_color_hover', array(
'label' => __('Text Color (Hover)', login_editor_title),
'section' => 'ds_login_text_section',
'priority' => 10,
'settings' => 'ds_login_text_color_hover'
)));
}
add_action('customize_register','ds_register_login_editor');
function ds_login_customizer(){
$ logo_url = get_option('ds_login_logo');
$ logo_width = get_option('ds_login_logo_width');
$ logo_height = get_option('ds_login_logo_height');
$ logo_padding = get_option('ds_login_logo_padding');
$ bg_img = get_option('ds_login_bg_image');
$ bg_color = get_option('ds_login_bg_color');
$ bg_size = get_option('ds_login_bg_size');
$ form_bg_image = get_option('ds_login_form_bg_image');
$ form_bg_color = get_option('ds_login_form_bg_color');
$ form_width = get_option('ds_login_form_width');
$ form_height = get_option('ds_login_form_height');
$ form_padding = get_option('ds_login_form_padding');
$ field_width = get_option('ds_login_field_width');
$ field_margin = get_option('ds_login_field_margin');
$ field_bg = get_option('ds_login_field_bg');
$ field_color = get_option('ds_login_field_color');
$ field_label = get_option('ds_login_field_label');
$ button_bg = get_option('ds_login_button_bg');
$ button_border = get_option('ds_login_button_border');
$ button_shadow = get_option('ds_login_button_shadow');
$ button_color = get_option('ds_login_button_color');
$ button_hover_bg = get_option('ds_login_button_hover_bg');
$ button_hover_border = get_option('ds_login_button_hover_border');
$ other_color = get_option('ds_login_text_color');
$ other_color_hover = get_option('ds_login_text_color_hover');
$ other_css = get_option('ds_login_custom_css');
?>
body.login {
background-image: url(<?php echo $bg_img; ?>) !important;
background-color: <?php echo $bg_color; ?> !important;
background-size: <?php echo $bg_size; ?> !important;
}
body.login #login h1 a {
background-image: url(<?php echo $logo_url; ?>) !important;
width: <?php echo $logo_width; ?> !important;
height: <?php echo $logo_height; ?> !important;
background-size: <?php echo $logo_width; ?> <?php echo $logo_height; ?> !important;
padding-bottom: <?php echo $logo_padding; ?> !important;
}
background-image: url(<?php echo $form_bg_image; ?>) !important;
background-color: <?php echo $form_bg_color; ?> !important;
height: <?php echo $form_height; ?> !important;
padding: <?php echo $form_padding; ?> !important;
border: <?php echo $form_border; ?> !important;
}
width: <?php echo $form_width; ?> !important;
}
.login形式.input,.login输入[type =“ text”] {
width: <?php echo $field_width; ?> !important;
margin: <?php echo $field_margin; ?> !important;
background: <?php echo $field_bg; ?> !important;
color: <?php echo $field_color; ?> !important;
}
.login标签{
color: <?php echo $field_label; ?> !important;
}
.wp-core-ui .button-primary {
background: <?php echo $button_bg; ?> !important;
border-color: <?php echo $button_border; ?> !important;
box-shadow: 0px 1px 0px <?php echo $button_shadow; ?> inset, 0px 1px 0px rgba(0, 0, 0, 0.15);
color: <?php echo $button_color; ?> !important;
}
.wp-core-ui .button-primary.focus,.wp-core-ui .button-primary.hover,.wp-core-ui .button-primary:focus,.wp-core-ui .button -primary:hover {
background: <?php echo $button_hover_bg; ?> !important;
border-color: <?php echo $button_hover_border; ?> !important;
}
.login #backtoblog a,.login #nav a {
color: <?php echo $other_color; ?> !important;
}
.login #backtoblog a:hover,.login #nav a:hover,.login h1 a:hover {
color: <?php echo $other_color_hover; ?> !important;
}
<?php echo $other_css; ?>
c)functions.php。您在这里需要的是
<?php
/ **
@author Divi Space
@copyright 2017
* /
如果(!defined('ABSPATH'))die();
function ds_ct_enqueue_parent(){wp_enqueue_style('parent-style',get_template_directory_uri()。'/style.css'); }
function ds_ct_loadjs(){
wp_enqueue_script( 'ds-theme-script', get_stylesheet_directory_uri() . '/ds-script.js',
array( 'jquery' )
);
}
add_action('wp_enqueue_scripts','ds_ct_enqueue_parent');
add_action('wp_enqueue_scripts','ds_ct_loadjs');
include('login-editor.php');
?>
d)ds-script.js,其中包含divi-space小组部署的一些JavaScript。它只有一行,但是当您需要通过子主题将自定义javascript添加到divi时会有所帮助
// Custom JS goes here ------------
最后,您可以添加一个名为screenshot.jpg的文件,在本例中为880x660 px
这就是您所需要的。有更简单的方法可以为Divi制作儿童主题,这在我需要时最适合我。所有的功劳归于生成器和上面的代码的创建者