【问题标题】:How do I get the dashboard to work properly with a child theme?如何让仪表板与子主题一起正常工作?
【发布时间】:2012-06-06 06:41:11
【问题描述】:

我已经安装了 Wordpress 并安装了一个基于 211 的子主题。我已将三个模板文件添加到包含子主题的目录中。它们是:

style.css

/*
Theme Name: Cinema Verde
Theme URI: http://wordpress.org/extend/themes/twentyeleven
Author: Arthur Ianuzzi - Omicron Marketing
Author URI: http://www.omicron-marketing.com
Description: Theme for Cinema Verde, child theme based on TwentyEleven
Version: 1.0
License: GNU General Public License
License URI: license.txt
Tags: dark, black, gray,  two-columns,  right-sidebar, fixed-width, custom-background, custom-colors, custom-header, custom-menu, editor-style, featured-image-header, featured-images, full-width-template, microformats, post-formats, rtl-language-support, sticky-post, theme-options, translation-ready
Template: twentyeleven
*/
@import url('../twentyeleven/style.css');

自定义样式.css

 #access { background: #000; border-top: 2px solid #84E41F; border-bottom: 2px solid #84E41F; }

#access a { color: #fff; }

#access a:focus { color: #fff;} 

#access ul ul :hover a { background: #000; color: #fff; }

#access li:hover a {color: #84E41F; background: #000; border-bottom: 0 ;  }

#branding #searchform {display:none; }

h1.entry-title {color: #84E41F;}

和functions.php

 <?php

/** Tell WordPress to run post_theme_setup() when the 'after_setup_theme' hook is run. */
add_action( 'after_setup_theme', 'post_theme_setup' );

if ( !function_exists( 'post_theme_setup' ) ):
function post_theme_setup() {

/* Add our new styles after all stylesheets have loaded */
function twentyeleven_enqueue_child_style() {
wp_enqueue_style( 'child_style', get_stylesheet_directory_uri() . '/custom-style.css', array(), null );
do_action( 'twentyeleven_enqueue_child_style', 'child_style' );
}
add_action( 'wp_enqueue_scripts', 'twentyeleven_enqueue_child_style', 11 );
}
endif;

?>

一切正常,除了当我在仪表板中更改某些内容时,确认页面出现空白。例如,如果我写了一篇新文章,然后点击“发布”,我会得到一个空白页面,而不是显示我刚刚写的文章的页面。

【问题讨论】:

    标签: wordpress wordpress-theming


    【解决方案1】:

    你在一个函数中运行一个函数,你的代码被破坏了......
    打开wp_debug,你会看到错误。

    /** Tell WordPress to run post_theme_setup() when the 'after_setup_theme' hook is run. */
    add_action( 'after_setup_theme', 'post_theme_setup' );
    
    if ( !function_exists( 'post_theme_setup' ) ):
    function post_theme_setup() {
    
        wp_enqueue_style( 'child_style', get_stylesheet_directory_uri() . '/custom-style.css', array(), null );
        do_action( 'twentyeleven_enqueue_child_style', 'child_style' );
    
        add_action( 'wp_enqueue_scripts', 'twentyeleven_enqueue_child_style', 11 );
    }
    endif;
    
    ?>
    

    旁注:
    您知道包含多个样式表会使您的网站变慢吗?
    顺便说一句,您正在使用 enqueue 很好

    【讨论】:

    • 非常感谢您的帮助。我还找到了一种更有效的方法来制作一个看起来像二十一“黑暗”主题的儿童主题。我切换回 light 主题,删除了子目录中的 functions.php 和 custom-style.css 文件,然后复制了 /themes/twentyeleven/colors/dark.css 的全部内容并将其附加到末尾子主题中 style.css 的内容。这最终变得更加高效且更易于定制。
    猜你喜欢
    • 2019-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-23
    • 2017-02-27
    • 2021-12-27
    • 2012-07-02
    • 1970-01-01
    相关资源
    最近更新 更多